Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.Net 2.0 - ControlPaint.DrawButton uses wrong color

Tags:

c#

.net

When I call ControlPaint.DrawButton, the button that is drawn is in the non-themed background color. How do I draw a control that looks like a button (including themed drawing) in .Net 2.0 (C#)?

like image 945
Brad Bruce Avatar asked Feb 03 '26 04:02

Brad Bruce


1 Answers

The ControlPaint methods do not support visual styles, that's why it looks all messed up (try taking out this line of code in your Program.cs Application.EnableVisualStyles(); and everything will look like that button and you'll see what I mean.)

The correct method you should be using is the ButtonRender.DrawButton(..) method. This does honor visual styles and will thus render correctly. Quick sample:

            ButtonRenderer.DrawButton(this.CreateGraphics(), 
            new Rectangle(20, 20, 100, 40),"Click me!",
            new Font(this.Font, FontStyle.Regular),false,
            System.Windows.Forms.VisualStyles.PushButtonState.Normal);
like image 143
BFree Avatar answered Feb 04 '26 18:02

BFree



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!