0

I have multiple buttons in a Panel. I want to hide the Panel on mouse leave of the panel, or buttons.

The problem is that when my cursor hovers on one button and hovers again on another button, the panel that holds the button will hide because I have panel.hide() code on each mouse_Leave event in the button and on the panel. I want to hide it when the cursor leaves the panel or the button.

Screenshot

Andrew Morton
  • 24,203
  • 9
  • 60
  • 84
GPlay
  • 9
  • 4
  • 1
    Your question, or at least what you are doing, is known in English as an OxyMoron. You want the Panel to `Hide` when the `Mouse` leaves the `Panel` or, when leaves a `Button` on the `Panel`. Then you seem not happy the `Panel` hides when you leave a `Button`, but that is what you are telling it to do. Think more about what it is you actually want. – video.baba Feb 16 '19 at 11:48
  • Think different what will hapen if the mouse cursor leave the current botton where the cursor hover – GPlay Feb 16 '19 at 12:42
  • You mention a "mouse_Leave" event - the event supplied by Windows Forms and WPF is named "MouseLeave" - have you made your own event? – Andrew Morton Feb 16 '19 at 14:59

1 Answers1

0

It sounds like you basically want the panel hidden at all times unless the cursor is over it, and when the cursor isn't the panel hides again?

You could try keeping the panel hidden by default so it's always that way unless the mouse enter's over it, then it shows. That way, when the mouse leaves the panel again it'll automatically hide.

J. Scott Elblein
  • 4,013
  • 15
  • 58
  • 94
  • but when i hover to the buttons the panel will hide again – GPlay Feb 16 '19 at 12:50
  • @GPlay You'd have to remove your current `.hide` calls in each mouse button. As long as you have the panel set to show only when the mouse is over it, all controls within the panel will stay visible as well, since a Panel control is a container control. – J. Scott Elblein Feb 16 '19 at 12:54
  • Have a look at this: https://stackoverflow.com/questions/8159534/net-how-to-check-if-the-mouse-is-in-a-control Then you could just do something like (Pseudo code) `if mouse is over panel1 then show panel1, else hide panel1` – J. Scott Elblein Feb 16 '19 at 13:02
  • when the cursor hover in the button inside the panel it will triger the event mouse leave of the panel – GPlay Feb 16 '19 at 13:13
  • 1
    I really want to help and give a code suggestion but I'm feeling confused! – video.baba Feb 16 '19 at 13:55
  • @J.ScottElblein The MouseLeave event *is* triggered for a Panel when the cursor moves from the Panel to a control within it. – Andrew Morton Feb 16 '19 at 15:08
  • @J.ScottElblein If you take what you have written in your first comment and some code from the page you linked to but in VB, you would have an answer. `Sub Panel1_MouseLeave(sender As Object, e As EventArgs) Handles Panel1.MouseLeave` `Dim pnl = DirectCast(sender, Panel)` `If Not (pnl.ClientRectangle.Contains(pnl.PointToClient(Cursor.Position))) Then ' mouse has left the panel`... – Andrew Morton Feb 16 '19 at 15:14