Reader Level:
Articles

Set a Button State in C#

By Mahesh Chand on May 18, 2010
This code snippet shows how to set a button state in Windows Forms.
  • 0
  • 0
  • 13998

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);

 

 

Mahesh Chand

Founder C# Corner, a member-contributions based community founded in 1999 focuses on character, values, learning, sharing, networking and career growth. Mahesh has been awarded prestigious... Read more

COMMENT USING

Trending up