[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework

Manually painting a ToolStripSplitButton

Alex Clark

7/17/2008 8:47:00 AM

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


4 Answers

v-lliu

7/17/2008 10:19:00 AM

0

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:
msdnmg@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default....
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/de....
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Alex Clark

7/17/2008 7:33:00 PM

0

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




>
> 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:
> msdnmg@microsoft.com.
>
> ==================================================
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/subscriptions/managednewsgroups/default....
> 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/de....
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>


v-lliu

7/18/2008 2:38:00 AM

0

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:
msdnmg@microsoft.com.

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

Alex Clark

7/19/2008 7:05:00 PM

0

Thanks Linda, you're a star :-D

-Alex

"Linda Liu[MSFT]" <v-lliu@online.microsoft.com> wrote in message
news:qB4DA9H6IHA.3320@TK2MSFTNGHUB02.phx.gbl...
> 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:
> msdnmg@microsoft.com.
>
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>