I am currently developing a custom control and realize that my code runs twice. This is not a very big problem (this is just a call to the Focus method). However, I would like to understand this.
From reading MSDN description for click | onclick , he claims that:
It is executed when the user presses the left mouse button on the object.
So, I added the OnClick event and MouseClick events to handle both left and right click. But after debugging the code, I found that OnClick handles events on the left and right.
Why does OnClick handle this, and I need both events in my code to be skipped for some reason?
protected override void OnClick(EventArgs e) { this.Focus(); base.OnClick(e); } private void CustomControl_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { rightClickMenu(e); } }
Billy source share