vb.net [Panel] .Select()on on OnMouseEnter即使面板没有聚焦也要滚动;这不起作用

时间:2015-02-13 06:34:39

标签: vb.net user-controls scroll panel mouseenter

这是我制作的自定义菜单,名为MenuM(用户控件类;见下图),由2个面板组成:MenuM_CaptionMenuMItems_Container。每个MenuMItem也是MenuMItems_Container面板中的用户控件。

Custom Menu

为了能够扼杀我的菜单(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?)

谢谢!

1 个答案:

答案 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