.Net 2.0 - ControlPaint.DrawButton uses the wrong color

When I call ControlPaint.DrawButton, the button that is drawn is in a colored background with no theme. How to create a control that looks like a button (including a theme image) in .Net 2.0 (C #)?

+3
source share
2 answers

ControlPaint methods do not support visual styles, so everything looks messy (try outputting this line of code in Program.cs Application.EnableVisualStyles () and everything will look like this button, and you will see what I mean.)

The correct method you should use is the ButtonRender.DrawButton (..) method . It performs clear visual styles and thus displays them correctly. Quick example:

            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);
+6
source

the first and second overload have ButtonStateas the last parameter.

I guess you want:, ButtonState.Normaland what you get is this ButtonState.Flat?

0
source

Source: https://habr.com/ru/post/1709735/


All Articles