J
jon morgan
Hi,
There seems to be a problem with mouse event handling in controls located on
MDI child forms in .net v1.1. When the control is first made visible it
receives the OnMouse Enter and OnMouseLeave events. If the child form is
then hidden and re-shown only the OnMouseEnter event fires - thereafter
neither event fires, although oddly, OnMouseMove continues to fire.
The code below demonstrates the problem. Form1 is the mdi container and
Form2 is a child form that contains a button control. The main menu item on
Form1 is used to toggle the visibility of Form2. The button is subclassed to
show when the events fire. When form2 is hidden and then re-displayed, the
OnMouseEnter event fires when the button is entered, thereafter neither
event fires until Form2 is re-loaded, but OnMouseMove continues to fire.
If this is a genuine bug, I'd be grateful for any workaround tips.
Thanks again,
Jon
-------------------------------------------------------------------------------------------
Imports System.Windows.Forms
Public Class Form1
Inherits Form
Public Sub New()
MyBase.New()
MainMenu1 = New MainMenu
MenuItem1 = New MenuItem
MainMenu1.MenuItems.AddRange(New MenuItem() {Me.MenuItem1})
MenuItem1.Index = 0
MenuItem1.Text = "Toggle"
Me.ClientSize = New System.Drawing.Size(200, 120)
Me.IsMdiContainer = True
Me.Menu = Me.MainMenu1
End Sub
Friend WithEvents MainMenu1 As MainMenu
Friend WithEvents MenuItem1 As MenuItem
Private WithEvents f2 As Form2
Private Sub MenuItem1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MenuItem1.Click
If f2 Is Nothing Then
f2 = New Form2
f2.Location = New Point(10, 10)
Me.AddOwnedForm(f2)
f2.MdiParent = Me
f2.Show()
Else
f2.Visible = Not f2.Visible
End If
End Sub
Private Sub f2_Closed(ByVal sender As Object, ByVal e As System.EventArgs)
Handles f2.Closed
f2.Dispose()
f2 = Nothing
End Sub
End Class
Public Class Form2
Inherits Form
Public Sub New()
MyBase.New()
Dim mb As New myButton
With mb
.Size = New Size(80, 30)
.Text = "winbtn1"
.Location = New Point(10, 10)
End With
Me.ClientSize = New System.Drawing.Size(120, 60)
Me.Controls.Add(mb)
End Sub
End Class
Friend Class myButton
Inherits Button
Protected Overrides Sub OnMouseEnter(ByVal e As System.EventArgs)
MyBase.OnMouseEnter(e)
Console.WriteLine("mybutton mouse enter")
End Sub
Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
MyBase.OnMouseLeave(e)
Console.WriteLine("mybutton mouse leave")
End Sub
Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
MyBase.OnMouseMove(e)
Console.WriteLine("mybutton mouse move")
End Sub
End Class
There seems to be a problem with mouse event handling in controls located on
MDI child forms in .net v1.1. When the control is first made visible it
receives the OnMouse Enter and OnMouseLeave events. If the child form is
then hidden and re-shown only the OnMouseEnter event fires - thereafter
neither event fires, although oddly, OnMouseMove continues to fire.
The code below demonstrates the problem. Form1 is the mdi container and
Form2 is a child form that contains a button control. The main menu item on
Form1 is used to toggle the visibility of Form2. The button is subclassed to
show when the events fire. When form2 is hidden and then re-displayed, the
OnMouseEnter event fires when the button is entered, thereafter neither
event fires until Form2 is re-loaded, but OnMouseMove continues to fire.
If this is a genuine bug, I'd be grateful for any workaround tips.
Thanks again,
Jon
-------------------------------------------------------------------------------------------
Imports System.Windows.Forms
Public Class Form1
Inherits Form
Public Sub New()
MyBase.New()
MainMenu1 = New MainMenu
MenuItem1 = New MenuItem
MainMenu1.MenuItems.AddRange(New MenuItem() {Me.MenuItem1})
MenuItem1.Index = 0
MenuItem1.Text = "Toggle"
Me.ClientSize = New System.Drawing.Size(200, 120)
Me.IsMdiContainer = True
Me.Menu = Me.MainMenu1
End Sub
Friend WithEvents MainMenu1 As MainMenu
Friend WithEvents MenuItem1 As MenuItem
Private WithEvents f2 As Form2
Private Sub MenuItem1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MenuItem1.Click
If f2 Is Nothing Then
f2 = New Form2
f2.Location = New Point(10, 10)
Me.AddOwnedForm(f2)
f2.MdiParent = Me
f2.Show()
Else
f2.Visible = Not f2.Visible
End If
End Sub
Private Sub f2_Closed(ByVal sender As Object, ByVal e As System.EventArgs)
Handles f2.Closed
f2.Dispose()
f2 = Nothing
End Sub
End Class
Public Class Form2
Inherits Form
Public Sub New()
MyBase.New()
Dim mb As New myButton
With mb
.Size = New Size(80, 30)
.Text = "winbtn1"
.Location = New Point(10, 10)
End With
Me.ClientSize = New System.Drawing.Size(120, 60)
Me.Controls.Add(mb)
End Sub
End Class
Friend Class myButton
Inherits Button
Protected Overrides Sub OnMouseEnter(ByVal e As System.EventArgs)
MyBase.OnMouseEnter(e)
Console.WriteLine("mybutton mouse enter")
End Sub
Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
MyBase.OnMouseLeave(e)
Console.WriteLine("mybutton mouse leave")
End Sub
Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
MyBase.OnMouseMove(e)
Console.WriteLine("mybutton mouse move")
End Sub
End Class