2

I have a big button and a small button above the big button. What I want is: when the user click on the small button, activate his click event and not the click event from the big button. Thanks!

EDIT: I have a form with 2 System.Windows.Forms.Button. Visual Studio 2017.

A image to ilustrate:

enter image description here

EDIT²: The smllButton starts invisible! MouseEnter event of bigButton: smallButton.Visible = true MouseLeave event of bigButton: smllButton.visible = false

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
Diego Bittencourt
  • 595
  • 10
  • 28

1 Answers1

1

One way is to use the MouseDown event on the big button to send a click to the little button:

private void bigButton_MouseDown(object sender, MouseEventArgs e) {
    if (littleButton.Bounds.Contains(littleButton.Parent.PointToClient(Cursor.Position))) {
        littleButton_Click(littleButton, EventArgs.Empty);
        return;
    }

    // Any code needed for MouseDown actually on big button goes here:
}

Note this makes it possible to drag the mouse from the little button to the big button and click both. You could move the big button's click code to this method instead.

An alternative would be to use only one button, change its appearance on MouseEnter, and use mouse X/Y to figure out which part of the button was clicked.

Bloopy
  • 305
  • 1
  • 9