Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# UseVisualStyleBackColor

Tags:

c#

Is there a way in which I can change the button color and preserve the Windows VisualStyle? I want to create a button that looks like checkBox2 (color and style)

alt text

this.button2.BackColor = System.Drawing.SystemColors.GradientActiveCaption;
this.button2.UseVisualStyleBackColor = false;  //if true, BackColor gets ignored
like image 725
Eric Fortis Avatar asked Dec 20 '10 19:12

Eric Fortis


1 Answers

No, not really. This kind of button background is drawn by VisualStyleRenderer.DrawBackground(). Which in turns pinvokes DrawThemeBackground(). These methods don't take a color. None is needed because the color is already specified in the theme.

Simulating the appearance with a LinearGradientBrush is your only real hope. Note that custom drawing a button is quite difficult, all the code is internal and no owner-draw is provided.

Consider using an image.

like image 56
Hans Passant Avatar answered Oct 09 '22 02:10

Hans Passant