事件顺序上的不同面板的MouseEnter和MouseLeave冲突 [英] Different Panels' MouseEnter and MouseLeave conflict on Event Order
问题描述
first_pnl
和 second_pnl
,第二个面板不是默认显示。初始想法我需要的: - 如果我的光标超过第一个(
MouseEnter
-
BackColor
将更改为Black - 第二个面板将可见
-
- 如果我的光标离开第一个(
MouseLeave
)
- 这是
BackColor
将改回格雷 - 第二个面板将不可见
- 这是
简单如下:
Private Sub PanelMouseEnter(sender As Object,e As EventArgs)_
处理first_pnl.MouseEnter
first_pnl.BackColor = Color.Black
second_pnl.Visible = True
End Sub
Private Sub PanelMouseLeave(sender As Object,e As EventArgs)_
处理first_pnl.MouseLeave
first_pnl.BackColor = Color.Gray
second_pnl.Visible = False
End Sub
但是我想要发生的是:
- 当光标移动到第二个面板(现在是可见的)
-
second_pnl
将保持 - 它维持
first_pnl
属性,就像在MouseEnter
事件
-
这里的情况要清楚:
这是我的逻辑私人子PanelMouseEnter(发件人作为对象,e作为EventArgs)
_
手柄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)_
处理first_pnl.MouseLeave ,second_pnl.MouseLeave
first_pnl.BackColor = Color.Gray
second_pnl.Visible = False
End Sub
看起来很合理,但我认为系统首先考虑 firstPnl
之前的 MouseLeave
它甚至考虑 MouseEnter
second_pnl
。
任何方式来做?
jmcilhinney的评论很容易解决。
Private Sub Form1_MouseEnter(ByVal sender As Object,ByVal e As System.EventArgs)处理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)处理first_pnl.MouseEnter
first_pnl.BackColor = Color.Black
second_pnl.Visible = True
End Sub
Here, I have two side-by-side panel the first_pnl
and second_pnl
, the second panel is not visible by default. Initial thoughts of what I need:
- If my cursor is over the the first one (
MouseEnter
)- It's
BackColor
would change to Black - Second panel would be visible
- It's
- If my cursor leaves first one (
MouseLeave
)- It's
BackColor
would change back to Gray - Second panel would not be visible
- It's
Which is simple as:
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
But what I want to happen is:
- When the cursor moves to the second panel (which by now is visible)
second_pnl
would remain visible unless the cursor leave its area.- It sustains
first_pnl
property as if it where on aMouseEnter
event
And here's the scenario to be clear:
And here's my logic of making that possible: (Giving their same events with same code)
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
Looks reasonable, but I think the system consider first the MouseLeave
of first_pnl
before it even consider the MouseEnter
of second_pnl
.
Any way to do it?
jmcilhinney's comment solves this easily.
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
这篇关于事件顺序上的不同面板的MouseEnter和MouseLeave冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!