在这里,我有first_pnl
和second_pnl
两个并排面板,默认情况下第二个面板不可见。我需要的初步想法:
MouseEnter
)之上
BackColor
会改为黑色MouseLeave
)
BackColor
会改回Gray 这很简单:
Private Sub PanelMouseEnter(sender As Object, e As EventArgs) _
Handles first_pnl.MouseEnter
first_pnl.BackColor = Color.Black
second_pnl.Visible = True
End Sub
Private Sub PanelMouseLeave(sender As Object, e As EventArgs) _
Handles first_pnl.MouseLeave
first_pnl.BackColor = Color.Gray
second_pnl.Visible = False
End Sub
但我想要发生的是:
second_pnl
将保持可见。first_pnl
属性,就像它在MouseEnter
事件这里的情况很清楚:
这就是我使这成为可能的逻辑:(用相同的代码给出相同的事件)
Private Sub PanelMouseEnter(sender As Object, e As EventArgs) _
Handles first_pnl.MouseEnter, second_pnl.MouseEnter
first_pnl.BackColor = Color.Black
second_pnl.Visible = True
End Sub
Private Sub PanelMouseLeave(sender As Object, e As EventArgs) _
Handles first_pnl.MouseLeave, second_pnl.MouseLeave
first_pnl.BackColor = Color.Gray
second_pnl.Visible = False
End Sub
看起来很合理,但我认为系统在考虑MouseLeave
的{{1}}之前,首先考虑first_pnl
MouseEnter
。
有办法吗?
答案 0 :(得分:1)
jmcilhinney's comment很容易解决这个问题。
Private Sub Form1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseEnter
first_pnl.BackColor = Color.Gray
second_pnl.Visible = False
End Sub
Private Sub first_pnl_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles first_pnl.MouseEnter
first_pnl.BackColor = Color.Black
second_pnl.Visible = True
End Sub