ControlStyles Enum
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Specifies the style and behavior of a control.
This enumeration supports a bitwise combination of its member values.
public enum class ControlStyles
[System.Flags]
public enum ControlStyles
[<System.Flags>]
type ControlStyles =
Public Enum ControlStyles
- Inheritance
- Attributes
Fields
Name | Value | Description |
---|---|---|
ContainerControl | 1 | If |
UserPaint | 2 | If |
Opaque | 4 | If |
ResizeRedraw | 16 | If |
FixedWidth | 32 | If |
FixedHeight | 64 | If |
StandardClick | 256 | If |
Selectable | 512 | If |
UserMouse | 1024 | If |
SupportsTransparentBackColor | 2048 | If |
StandardDoubleClick | 4096 | If |
AllPaintingInWmPaint | 8192 | If |
CacheText | 16384 | If |
EnableNotifyMessage | 32768 | If |
DoubleBuffer | 65536 | If |
OptimizedDoubleBuffer | 131072 | If |
UseTextForAccessibility | 262144 | Specifies that the value of the control's |
ApplyThemingImplicitly | 524288 | For certain UI-related color modes (Dark Mode/Light Mode), controls can opt-in to automatically apply the appropriate theming. Especially controls which are utilizing system-managed scrollbars can benefit from this setting. Note that using this settings will cause some win32 control theming renderers to become inactive for a specific theme. |
Examples
The following example demonstrates a use of ControlStyles with the StyleChanged event.
private:
// Set the 'FixedHeight' and 'FixedWidth' styles to false.
void MyForm_Load( Object^ /*sender*/, EventArgs^ /*e*/ )
{
this->SetStyle( ControlStyles::FixedHeight, false );
this->SetStyle( ControlStyles::FixedWidth, false );
}
void RegisterEventHandler()
{
this->StyleChanged += gcnew EventHandler( this, &MyForm::MyForm_StyleChanged );
}
// Handle the 'StyleChanged' event for the 'Form'.
void MyForm_StyleChanged( Object^ /*sender*/, EventArgs^ /*e*/ )
{
MessageBox::Show( "The style releated to the 'Form' has been changed" );
}
// Set the 'FixedHeight' and 'FixedWidth' styles to false.
private void MyForm_Load(object sender, EventArgs e)
{
this.SetStyle(ControlStyles.FixedHeight, false);
this.SetStyle(ControlStyles.FixedWidth, false);
}
private void RegisterEventHandler()
{
this.StyleChanged += new EventHandler(MyForm_StyleChanged);
}
// Handle the 'StyleChanged' event for the 'Form'.
private void MyForm_StyleChanged(object sender, EventArgs e)
{
MessageBox.Show("The style releated to the 'Form' has been changed");
}
' Set the 'FixedHeight' and 'FixedWidth' styles to false.
Private Sub MyForm_Load(sender As Object, e As EventArgs)
Me.SetStyle(ControlStyles.FixedHeight, False)
Me.SetStyle(ControlStyles.FixedWidth, False)
End Sub
Private Sub RegisterEventHandler()
AddHandler Me.StyleChanged, AddressOf MyForm_StyleChanged
End Sub
' Handle the 'StyleChanged' event for the 'Form'.
Private Sub MyForm_StyleChanged(sender As Object, e As EventArgs)
MessageBox.Show("The style releated to the 'Form' has been changed")
End Sub
Remarks
Controls use this enumeration in various properties and methods to specify functionality. A control can enable a style by calling the SetStyle method and passing in the appropriate ControlStyles bit (or bits) and the Boolean value to set the bit(s) to. For example, the following line of Visual Basic code would enable double-buffering.
myControl.SetStyle(UserPaint Or AllPaintingInWmPaint Or DoubleBuffer, True)
If the AllPaintingInWmPaint bit is set to true
, the window message WM_ERASEBKGND is ignored, and both OnPaintBackground and OnPaint methods are called directly from the window message WM_PAINT. This generally reduces flicker unless other controls send the window message WM_ERASEBKGND to the control. You might send the window message WM_ERASEBKGRND to achieve a pseudo-transparent effect similar to SupportsTransparentBackColor; for example, a ToolBar with flat appearance does this.
To fully enable double-buffering, you can set the OptimizedDoubleBuffer and AllPaintingInWmPaint bits to true
. However the preferred method for enabling double buffering, which yields the same result, is to set the DoubleBuffered property for the control to true
.
If the SupportsTransparentBackColor bit is set to true
, and the BackColor is set to a color whose alpha component is less than 255, OnPaintBackground will simulate transparency by asking its parent control to paint the background. This is not true transparency.
Note
If there is another control between the control and its parent, the current control will not show the control in the middle.
When the UserMouse bit is set to true
, the following methods are still called: Control.OnMouseDown, Control.OnMouseUp, Control.OnMouseEnter, Control.OnMouseMove, Control.OnMouseHover, Control.OnMouseLeave, and Control.OnMouseWheel.
When the control is clicked, if the StandardClick bit is set to true
the Control.OnClick method is called and it raises the Control.Click event. When the control is double-clicked, and both the StandardClick and StandardDoubleClick bits are set to true
, the click is passed on to the DoubleClick event. Then the Control.OnDoubleClick method is called and it raises the Control.DoubleClick event. However, the control can call OnClick or OnDoubleClick directly regardless of the StandardClick and StandardDoubleClick bit values. For more information on control click and double click behaviors, see the Control.Click and Control.DoubleClick topics.
When the UseTextForAccessibility bit is set and there is a value in the control's Text
property, the value of that control's Text
property determines the control's default Active Accessibility name and shortcut key. Otherwise, the text of the preceding Label control will be used instead. This style is set by default. Certain built-in control types, such as TextBox and ComboBox, reset this style so that the Text
property of those controls will not be used by Active Accessibility.