tags:

views:

241

answers:

2

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#)?

A: 

The first and second overload have ButtonState as the last param.

I imagine you want: ButtonState.Normal, and what you're getting is ButtonState.Flat ?

John Weldon
I'm using normal and the borders look good, but not the background. There doesn't seem to be a button version of ComboBoxRenderer. Bummer.
Brad Bruce
+4  A: 

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);
BFree
I looked for that for hours... Thanks.
Brad Bruce