Mouse behavior of ToolStripMenuItems

G

Guest

I've noticed that if you click on a Windows.Forms.ToolStripButton then a
MouseLeave event will not occur until the button is released.
ToolStripMenuItems on the other hand will raise a MouseLeave event as soon as
the mouse moves outside of the item, even if the mouse button is held down.

You can observe this behavior using the following sample:

Public Class Form1
Inherits Windows.Forms.Form
Public Sub New()
Dim item1 As New Windows.Forms.ToolStripMenuItem("Item")
Dim item2 As New Windows.Forms.ToolStripButton("Button")
Dim ts As New Windows.Forms.ToolStrip
ts.Items.AddRange(New Windows.Forms.ToolStripItem() {item1, item2})
Me.Controls.Add(ts)
End Sub
End Class

I understand that this behavior is normally desirable and that in most cases
you would just use a ToolStripButton, but I have a situation where is would
be very helpful to have a ToolStripMenuItem behave like a ToolStripButton in
regards to the mouse. Is there any way to do this?

Thanks for any help!
Lance
 
L

Linda Liu [MSFT]

Hi Lance,

I performed a test based on your sample code, but I saw the MouseLeave
event of the ToolStripButton was fired as soon as the mouse moved outside
of the item, even if the mouse button was held down.

I saw the same thing on ToolStripMenuItem.

I have tried to prevent the MouseLeave event of ToolStripButton or
ToolStripMenuItem from being fired when the left mouse button is held down.
I derive the ToolStripButton and override the OnMouseLeave method. I
thought I could prevent the MouseLeave event of the derived ToolStripButton
from occurring by not calling the statement 'MyBase.OnMouseLeave(e)' in the
override OnMouseLeave method. Unfortunately, I found that this could not
prevent the event from occurring.

It seems that it's the ToolStrip that fires the MouseLeave event for each
item in it.

Could you please tell me why you'd like the behavior of preventing the
MouseLeave event from occurring when the left mouse button is held down?
Maybe there's another way to accomplish what you want.


Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

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