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
2009-06-04 03:30:30
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
2009-06-04 03:40:19
+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
2009-06-04 03:39:50