This article has been
excerpted from book "
Windows Forms and controls provide built-in support for double buffering, and
the SetStyle method of the Control class plays a vital role in this process.
Before we discuss how to use SetStyle, let's take a look at this method and its
members.
The SetStyle method is defined in System.Windows.Forms.Controller, which sets
the specified style of a control. This method takes two arguments. The first
argument is of type ControlStyle enumeration, and it represents the style of the
control. The second argument is true if we want to apply the specified style,
false otherwise. The members of the ControlStyle enumeration are described in
Table 13.1.
TABLE 13.1: ControlStyle members
| Member | Description |
| AllPaintingInWmPaint | The WM_ERASEBKGND window message is sent to the message queue whenever a control needs to redraw its background. This method tells Windows to ignore the message, reducing clicker. Both OnPaint and OnPaintBackGround are called from the window message WM_Paint. AllPaintingInWmPaint should be used only if UserPaint is set to true. |
| CacheText | Applications can cache text using this option. The control keeps a copy of the text rather than getting it from the handle each time it is needed. This style default to false. |
| ContainerControl DoubleBuffer | The control is a container. This method provides built-in support for double buffering. When it is set to true, drawing is performed in a buffer and displayed only when complete. When using this option, you must also set the UserPaint and AllPaintingInWmPaint bits to true. |
| EnableNotifyMessage | If true, the OnNotifyMessage method is called for every message sent to the control's WindProc method. This style defaults to false. |
| FixedHeight | The control has a fixed height. |
| FixedWidth | The control has a fixed width. |
| Opaque | The control is drawn opaque, and the background is not painted. |
| ResizeRedraw | The control is redrawn when it is resized. |
| Selectable | The control can receive focus |
| StandardClick | The control implements standard click behavior. |
| StandardDoubleClick | The control implements standard double-click behavior. When using this option, you must also set StandardClick to true. |
| SupportsTransparentBackColor | The control accepts a Color object with alpha transparency for the background color. The UserPaint bit must be set to true, and the control must be derived from the Control class, like this: this.SetStyle(ControlStyle.UserPaint, true); |
| UserMouse | The control does its own mouse processing, and mouse events are not handled by the operating system. |
| UserPaint | The control paints itself rather than having the operating system do it. This option applies to classes derived from Control. |


Join the conversation! Your thoughts help the community grow.