Reader Level:
ARTICLE

Set a Button State in C#

Posted by Mahesh Chand Articles | How do I May 18, 2010
This code snippet shows how to set a button state in Windows Forms.
  • 0
  • 0
  • 12570

Button control has five states - Normal, Flat, Inactive, Pushed, and All. ButtonState enumeration represents a button state.

Windows Forms does not have a straight-forward way to set a button control state.

However, there is a way do to this J.

Windows Forms has a ControlPaint class with some static methods that can be used to draw various controls at runtime. The DrawButton method is used to draw a Button control and the last parameter of this method is ButtonState enumeration.

The following code snippet sets the button state of button1 using ControlPaint class.

ControlPaint.DrawButton(System.Drawing.Graphics.FromHwnd(button1.Handle),

            0, 0, button1.Width, button1.Height, ButtonState.Pushed);

 

 

COMMENT USING

Trending up