REPOST: MDI OnMouseLeave Problem

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
 
J

jon morgan

Hi jeff,

I don't know what you have to do to get a reply - I can't believe MS aren't
aware of the problem. From searching around the net I'm clear we're not
alone .

I suppose it'll be quietly fixed in Whidbey but it's frustrating in the
meantime as my app. is otherwise ready for deployment. The only workaround I
can come up with is re-creating the controls each time they're shown - bit
kludgy especially as I'll have to persist the data.

I'll repost if there's no reply in a few days.

Regards

Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top