I'm creating an application in C# using WinForms.
What I want:
I want a button with an arrow on the side. When the part of the button with the arrow is pressed it will display a drop down but if any other part of the button is pressed then it should trigger a mouse click event.
What I need help with:
I'm confident I can do the mouse positional check by using the mouse position, but how can I make sure the event handler for instances of the button only have a 'mouse button down' event when it was the main part of the button that was clicked? I.e. how do I eat the event in the base handler so it never reaches derived one?
What I have:
My code structure (simplified) is as follows (taken from Windows.Forms button with drop-down menu):
// Button class:
public class ButtonWithDropDown : Button
{
protected override void OnClick(EventArgs e)
{
// Check for when the mouse is on the button and dispose of the
// event if it's over the 'arrow' part of the button.
}
}
// Event handler:
private void btnClickMe_Click(object sender, EventArgs e)
{
MouseEventArgs mevent = (MouseEventArgs)e;
if (mevent.Button == System.Windows.Forms.MouseButtons.Left)
MessageBox.Show("Only shown when clicking the main part of the button");
}
Thanks.