Specify a region for a ToolStripItem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to create a Windows.Forms.ToolStripItem that behaves as if it is an
ellipse (e.g., similar to the round Office Button in Office 2007). Drawing
the item is no problem, but I also want to prevent the item from reponding to
the mouse unless the mouse is within the elliptical bounds of the item. For
a Windows.Forms.Control this can be done by setting the Region property, but
as far as I can tell there no such property for a ToolStripItem.

Thanks for any help!
Lance
 
Hi Lance,

Yes, you're right. Only Control class has the Region property.
ToolStripItem is derived from Component class, so it doesn't have a Region
property.

I have spent several hours researching on this problem, but unfortunately I
haven't found a solution yet.

I suggest that you use a Button instead of ToolStripItem. You may paint the
button by handling its Paint event and then set the button's Region
property.

FYI, you may visit the following link to get a sample code.

'Control.Region Property'
http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.region
.aspx

Hope this helps.
If you have any concerns, please feel free to let me know.


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.
 
Hi Linda,

Thank you so much for your time and your suggestion. Using a Button is a
good idea, but I would prefer to use a class that inherits from ToolStripItem
if at all possible in order to maintain internal consistency. Also, it might
be difficult to have a Button behave exactly like a ToolStripItem (with
DropDown items, etc.).

If it is not possible to associate a region with a ToolStripItem, then is
there some way to prevent the ToolStripItem from thinking that the mouse is
has entered it? I would guess that there is some method (probably either in
ToolStrip or ToolStripItem) where the hit test logic is being performed. If
it is possible to override that method then I could include custom logic for
handling elliptical ToolStripItems.

Thanks again,
Lance
 
Hi Lance,

In fact, I have spent some time researching on how to prevent the
ToolStripItem from being focused when the mouse is not located in the
'region'. But unfortunately, I haven't worked it out yet.

I will go on research and will get the result back to you ASAP.

I appreciate your patience.


Sincerely,
Linda Liu
Microsoft Online Community Support
 
Hi Lance,

We could subscribe the MouseMove event of a ToolStripItem and write our hit
test logic in the event handler. However, the problem is that it may not
easy to implement hit test logic since the 'region' is just a graph we draw.

What's more, it is may not easy to get the area only within the 'region'
focused when the mouse is located in the 'region', either.

I still suggest that you use a Button. As for the drop down items, you may
use ContextMenuStrip and call the Show method of the ContextMenuStrip in
the Button's Click event handler.

The following is a sample.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Me.ContextMenuStrip1.Show(Me.Button1, 0, Me.Button1.Height)
End Sub

Hope this helps.
If you have any concerns, please feel free to let me know.


Sincerely,
Linda Liu
Microsoft Online Community Support
 
Hi Linda,

Ok, I suspect that I will be able to implement some kind of workaround.
Thanks for your help and for the suggestion of using a Button.

Lance
 
Back
Top