Export (0) Print
Expand All
Expand Minimize

ControlStyles Enumeration

Specifies the style and behavior of a control.

This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

[FlagsAttribute]
public enum class ControlStyles

Member nameDescription
ContainerControlIf true, the control is a container-like control.
UserPaintIf true, the control paints itself rather than the operating system doing so. If false, the Paint event is not raised. This style only applies to classes derived from Control.
OpaqueIf true, the control is drawn opaque and the background is not painted.
ResizeRedrawIf true, the control is redrawn when it is resized.
FixedWidthIf true, the control has a fixed width when auto-scaled. For example, if a layout operation attempts to rescale the control to accommodate a new Font, the control's Width remains unchanged.
FixedHeightIf true, the control has a fixed height when auto-scaled. For example, if a layout operation attempts to rescale the control to accommodate a new Font, the control's Height remains unchanged.
StandardClickIf true, the control implements the standard Click behavior.
SelectableIf true, the control can receive focus.
UserMouseIf true, the control does its own mouse processing, and mouse events are not handled by the operating system.
SupportsTransparentBackColorIf true, the control accepts a BackColor with an alpha component of less than 255 to simulate transparency. Transparency will be simulated only if the UserPaint bit is set to true and the parent control is derived from Control.
StandardDoubleClickIf true, the control implements the standard DoubleClick behavior. This style is ignored if the StandardClick bit is not set to true.
AllPaintingInWmPaintIf true, the control ignores the window message WM_ERASEBKGND to reduce flicker. This style should only be applied if the UserPaint bit is set to true.
CacheTextIf true, the control keeps a copy of the text rather than getting it from the Handle each time it is needed. This style defaults to false. This behavior improves performance, but makes it difficult to keep the text synchronized.
EnableNotifyMessageIf true, the OnNotifyMessage method is called for every message sent to the control's WndProc. This style defaults to false. EnableNotifyMessage does not work in partial trust.
DoubleBufferIf true, drawing is performed in a buffer, and after it completes, the result is output to the screen. Double-buffering prevents flicker caused by the redrawing of the control. If you set DoubleBuffer to true, you should also set UserPaint and AllPaintingInWmPaint to true.
OptimizedDoubleBufferIf true, the control is first drawn to a buffer rather than directly to the screen, which can reduce flicker. If you set this property to true, you should also set the AllPaintingInWmPaint to true.
UseTextForAccessibilitySpecifies that the value of the control's Text property, if set, determines the control's default Active Accessibility name and shortcut key.

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.

NoteNote:

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.

Notes to Inheritors:

Inheriting from a standard Windows Forms control and changing the StandardClick or StandardDoubleClick bit values to true can cause unexpected behavior or can have no effect at all if the control does not support the Click or DoubleClick events.

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

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft