这是图像和代码.....但是,它对我不起作用。专家,请告诉我哪里错误???
图片在这里: https://drive.google.com/open?id=1rUBq68ULDkTiFFv2uEiV_oQIh3wQIfhd
Private Sub PanelHome_MouseEnter(sender As Object, e As EventArgs) Handles PanelHome.MouseEnter
PanelHome.BackColor = Color.FromArgb(100, 25, 181, 254)
End Sub
Private Sub PanelHome_MouseLeave(sender As Object, e As EventArgs) Handles PanelHome.MouseLeave
PanelHome.BackColor = Color.FromArgb(255, 25, 181, 254)
End Sub
Private Sub PanelTuner_MouseEnter(sender As Object, e As EventArgs) Handles PanelTuner.MouseEnter
PanelTuner.BackColor = Color.FromArgb(50, 25, 181, 254)
End Sub
Private Sub PanelTuner_MouseLeave(sender As Object, e As EventArgs) Handles PanelTuner.MouseLeave
PanelTuner.BackColor = Color.FromArgb(255, 25, 181, 254)
End Sub
Private Sub PanelContents_MouseEnter(sender As Object, e As EventArgs) Handles PanelContents.MouseEnter
PanelContents.BackColor = Color.FromArgb(50, 25, 181, 254)
End Sub
Private Sub PanelContents_MouseLeave(sender As Object, e As EventArgs) Handles PanelContents.MouseLeave
PanelContents.BackColor = Color.FromArgb(255, 25, 181, 254)
End Sub
Private Sub PanelAboutUs_MouseEnter(sender As Object, e As EventArgs) Handles PanelAboutUs.MouseEnter
PanelAboutUs.BackColor = Color.FromArgb(50, 25, 181, 254)
End Sub
Private Sub PanelAboutUs_MouseLeave(sender As Object, e As EventArgs) Handles PanelAboutUs.MouseLeave
PanelAboutUs.BackColor = Color.FromArgb(255, 25, 181, 254)
End Sub
Private Sub PanelWriteToUs_MouseEnter(sender As Object, e As EventArgs) Handles PanelWriteToUs.MouseEnter
PanelWriteToUs.BackColor = Color.FromArgb(50, 25, 181, 254)
End Sub
Private Sub PanelWriteToUs_MouseLeave(sender As Object, e As EventArgs) Handles PanelWriteToUs.MouseLeave
PanelWriteToUs.BackColor = Color.FromArgb(255, 25, 181, 254)
End Sub
编辑1:面板的底座设置为 填充 ....
答案 0 :(得分:0)
即使面板的底座是Fill,你的代码也适合我...... 我认为你应该试着找出问题所在。 如果我创建一个包含2个面板的表单,一个停靠到TOP,另一个停靠到FILL,您的代码适用于我,使用事件MouseEnter和MouseLeave ... 您的问题不是dock属性,而不是使用的事件。
如果仍然找不到问题,可以先从新表单开始,然后逐步添加代码,直到找到使程序停止工作的步骤。
答案 1 :(得分:0)
只有鼠标触及面板本身时才会引发鼠标事件。如果面板内有其他控件,那么当鼠标悬停在他们上面时,他们的鼠标事件就会被提升。
在您的图片中,您似乎有PictureBox
覆盖每个面板,这意味着您必须处理其MouseEnter
和MouseLeave
事件以及这个工作:
Private Sub PanelHome_MouseEnter(sender As Object, e As EventArgs) Handles PanelHome.MouseEnter, PictureBoxHome.MouseEnter PanelHome.BackColor = Color.FromArgb(100, 25, 181, 254) End Sub Private Sub PanelHome_MouseLeave(sender As Object, e As EventArgs) Handles PanelHome.MouseLeave, PictureBoxHome.MouseLeave 'Check if the mouse is still inside the control's bounds. If Not PanelHome.DisplayRectangle.Contains(Cursor.Position) Then PanelHome.BackColor = Color.FromArgb(255, 25, 181, 254) End If End Sub
(您还需要对其余代码执行相同操作)
但是,如果您不需要以除背景颜色之外的任何其他方式更改这些面板,那么最好移除面板并仅保留图片框。