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.

[Visual Basic]
<Flags>
<Serializable>
Public Enum ControlStyles
[C#]
[Flags]
[Serializable]
public enum ControlStyles
[C++]
[Flags]
[Serializable]
__value public enum ControlStyles
[JScript]
public
   Flags
 Serializable
enum ControlStyles

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 must set the UserPaint, AllPaintingInWmPaint, and DoubleBuffer bits 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.

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.

Members

Member name Description Value
AllPaintingInWmPaint If 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. 8192
CacheText If 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. 16384
ContainerControl If true, the control is a container-like control. 1
DoubleBuffer If 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. To fully enable double-buffering, you must also set the UserPaint and AllPaintingInWmPaint style bits to true. 65536
EnableNotifyMessage If true, the OnNotifyMessage method is called for every message sent to the control's WndProc. This style defaults to false. 32768
FixedHeight If 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. 64
FixedWidth If 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. 32
Opaque If true, the control is drawn opaque and the background is not painted. 4
ResizeRedraw If true, the control is redrawn when it is resized. 16
Selectable If true, the control can receive focus. 512
StandardClick If true, the control implements the standard Click behavior. 256
StandardDoubleClick If true, the control implements the standard DoubleClick behavior. This style is ignored if the StandardClick bit is not set to true. 4096
SupportsTransparentBackColor If 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. 2048
UserMouse If true, the control does its own mouse processing, and mouse events are not handled by the operating system. 1024
UserPaint If true, the control paints itself rather than the operating system doing so. This style only applies to classes derived from Control. 2

Example

The following example enables double-buffering on a Form and updates the styles to reflect the changes.

Requirements

Namespace: System.Windows.Forms

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

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

See Also

System.Windows.Forms Namespace | Control.SetStyle | Control.GetStyle

Show:
© 2014 Microsoft