Manually painting a ToolStripSplitButton

  • Thread starter Thread starter Alex Clark
  • Start date Start date
A

Alex Clark

Hi all,

I'm handling all the painting for a ToolStrip in my app due to some
specialised requirements. Most of it has been relatively easy with a bit of
trial error, but I've hit a stumbling block when trying to draw a
ToolStripSplitButton.

I'm overriding the OnRenderSplitButtonBackground sub, and I *do* call
MyBase.OnRenderSplitButtonBackground(e), but I'm not getting the dropdown
chevron at all.

My ToolStripDropDownButtons paint the chevron themselves with no fuss, and
I'd really like to maintain consistency by keeping all the dropdown chevrons
identical.

I understand if I have to manually add the chevron myself, but is there a
predefined method for doing this? I checked through all of the ControlPaint
class and the SystemIcons class, but neither one appears to contain the
chevron for a ToolStripSplitButton's dropdown.

TIA,
~Alex
 
Hi Alex,
I'm overriding the OnRenderSplitButtonBackground sub, and I *do* call
MyBase.OnRenderSplitButtonBackground(e), but I'm not getting the dropdown
chevron at all.

The OnRenderSplitButtonBackground method is not relevant to the drawing of
the dropdown chevron.

Do you override the OnRenderArrow method in your derived ToolStripRenderer
class? If so, call the base.OnRenderArrow(e) method in the override method
in order to draw the default dropdown chevron.

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

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
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,
Do you override the OnRenderArrow method in your derived ToolStripRenderer
class? If so, call the base.OnRenderArrow(e) method in the override method
in order to draw the default dropdown chevron.

Nope, not overriding OnRenderArrow at all. I just tried overriding it and
calling the base method to see if that made any difference, but it didn't.

I should probably have mentioned that my toolstrip rendering class inherits
from ToolStripRenderer, *not* ToolStripProfessionalRenderer. If I alter it
to inherit from ToolStripProfessionalRenderer, I get the dropdown chevrons
appearing on my splitbuttons, but it interferes with other drawing that I'm
doing so I can't really use that as a solution.

Any ideas?

Thanks,
Alex
 
Hi Alex,

Thank you for your quick response!

I perform a test creating a new class derived from the ToolStripRenderer
class. I don't override any methods in the derived class. Then I use this
custom ToolStripRenderer on a ToolStrip that contains a
ToolStripSplitButton. When I run the application, I don't see an arrow
drawn in the dropdown button part of the ToolStripSplitButton as you said.

If I derive the custom renderer class from the
ToolStripProfessionalRenderer class and don't override any methods, the
arrow is drawn in the dropdown part of the ToolStripSplitButton. So it's
obvious that the ToolStripProfessionalRenderer class paints the arrow by
itself.

Using Reflector, I find that the ToolStripProfessionalRenderer class calls
the base.DrawArrow method in the override OnRenderSplitButtonBackground
method. This is the answer!

So the solution to your question is to call the base.DrawArrow method in
the override OnRenderSplitButtonBackground method. The following is a
sample:

class MyRender : ToolStripRenderer
{
protected override void
OnRenderSplitButtonBackground(ToolStripItemRenderEventArgs e)
{
base.OnRenderSplitButtonBackground(e);
ToolStripSplitButton item = e.Item as ToolStripSplitButton;
base.DrawArrow(new
ToolStripArrowRenderEventArgs(e.Graphics, item, item.DropDownButtonBounds,
SystemColors.ControlText, ArrowDirection.Down));
}
}

I have tested this in my application and it works on my side.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

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