这是我制作的自定义菜单,名为MenuM
(用户控件类;见下图),由2个面板组成:MenuM_Caption
和MenuMItems_Container
。每个MenuMItem
也是MenuMItems_Container
面板中的用户控件。
为了能够扼杀我的菜单(MenuMItems_Container
面板),我必须选择任何MenuMItem
,否则面板MenuMItems_Container
根本不会滚动,即使在写一个时也是如此以下命令(或两者):
1)在包含MenuM
实例作为控件的主窗体中:
Public Partial Class MyForm 'System.Windows.Forms.Form
Private Sub MenuM1_MouseEnter(sender As Object, e As System.EventArgs) Handles MenuM1.MouseEnter
Me.MenuM1.Select()
End Sub
End Class
2)和/或MenuM
类
Public Class MenuM
Private Sub MenuMItems_Container_MouseEnter(sender As Object, e As System.EventArgs) Handles MenuMItems_Container.MouseEnter
Me.MenuMItems_Container.Select()
End Sub
End Class
处理程序没有输入MenuMItems_Container.MouseEnter
事件。我认为原因是因为MenuMItem
类在容器可以处理/引发相同事件之前引发事件。
有人知道该怎么做才能解决这个问题吗? (Me.Parent.Select()
班级OnMouseEnter()
内的MenuMItem
?)
谢谢!
答案 0 :(得分:0)
这有效:
在班级MenuM
内:
Protected Overrides Sub OnGotFocus(e As System.EventArgs)
MyBase.OnGotFocus(e)
Me.MenuMItems_Container.Select()
End Sub
Private Sub MenuMItems_Container_MouseEnter(sender As Object, e As System.EventArgs) Handles MenuMItems_Container.MouseEnter
Me.MenuMItems_Container.Select() 'if no MenuMItems or less then MenuMItems_Container Height
End Sub
Private Sub MenuM_Caption_MouseEnter(sender As Object, e As System.EventArgs) Handles MenuM_Caption.MouseEnter
Me.MenuMItems_Container.Select()
End Sub
在课程MenuMItem
Protected Overrides Sub OnMouseEnter(e As System.EventArgs)
MyBase.OnMouseEnter(e)
Me.Parent.Select()
End Sub