简体   繁体   English

VB.net中面板上的按钮

[英]Buttons on a Panel in VB.net

I have a panel that has 3 buttons adjacent to each other. 我有一个具有彼此相邻的3个按钮的面板。 Collectively, the buttons are the same size as the panel. 总的来说,按钮的大小与面板的大小相同。 How do I make the Panel1_MouseLeave event fire, since the buttons take up all of the panel? 由于按钮占据了所有面板,如何触发Panel1_MouseLeave事件?

When you hover over the buttons, the Panel1_MouseLeave will get fired. 将鼠标悬停在按钮上时,将触发Panel1_MouseLeave。 You could use a combination of button_MouseLeave and Panel1_MouseLeave to determine when the mouse has actually left the control. 您可以结合使用button_MouseLeave和Panel1_MouseLeave来确定鼠标何时真正离开控件。

Or as suggested above, make the buttons 1px smaller than the panel. 或按照上面的建议,使按钮比面板小1px。 When the MouseLeave() gets fired, check the mouse location. 当MouseLeave()被触发时,检查鼠标位置。 If it is in the bound of the panel, you have not left. 如果它在面板的边界内,则您尚未离开。 If it is outside the bounds, then you have left. 如果它超出范围,那么您就离开了。

Add a timer to your form and check the mouse position: 在表单中添加一个计时器并检查鼠标位置:

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
  If Panel1.ClientRectangle.Contains(Panel1.PointToClient(MousePosition)) Then
    If Not insidePanel Then
      insidePanel = True
      // do something...
    End If
  Else
    If insidePanel Then
      insidePanel = False
      // do something
    End If
  End If
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM