I am experiencing an odd behaviour of the Capture property in a Form. I am setting it to true and subscribing to the mouse click event in the form to check if the event is being fired every time the mouse is clicked inside the client area of the form. In a simple test with a form and three buttons I am seeing that the capture works well only on the first attempt, and the event handler is not called afterwards. Here is the code:
public partial class Form1 : Form
{
public Form1()
{
//Form1 has three buttons that are created inside InitializeComponent. It also subscribes Form1_MouseClick handler to the MouseClick event of the Form
InitializeComponent();
// Setting Capture to true will force to handle any mouse click on any control in the form
Capture = true;
}
private void Form1_MouseClick(object sender, MouseEventArgs e)
{
// This message box should appear after any click in the form or control inside it
MessageBox.Show("Click!");
}
}
I have also tried subscribing to MouseCaptureChanged event to reenable Capture property to true, but with no success. Could anyone explain to me the reason of this behaviour?