Button State in VB.NET

This code snippet shows how to set a button state in Windows Forms.
  • 3549

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

 
Here is the VB.NET code:

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

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

Categories

More Articles

© 2013 dotNetheaven. All rights reserved.