This enumeration is used by Control.SetStyle() to
enable or disable a variety of different features in a custom
control.
Several features relate to the painting of the control.
AllPaintingInWmPaint causes both the
OnPaint() and OnPaintBackground() methods to be called during WM_PAINT
handling, rather than WM_PAINT and
WM_ERASEBACKGROUND as normal.
UserPaint indicates to the platform that you will
be painting the control yourself, rather than relying on the
operating system to do it for you (i.e., your control does not wrap a
Win32 control and you therefore expect to handle
WM_PAINT yourself).
DoubleBuffer enables automatic double buffering
for your control. A back buffer is created before OnPaint() is called, and the
System.Drawing.Graphics surface for that buffer is
passed to your paint handler. When you complete your painting, the
buffer is blitted to the window surface, dramatically reducing the
amount of flicker that occurs when you paint, at the cost of one
extra blit into the window, and potentially an awful lot of extra
committed memory for the back buffer. To get double buffering to work
properly, you should also set AllPaintingInWmPaint
(to prevent two separate blits for the background and the foreground,
which will induce flicker) and UserPaint.
SupportsTransparentBackColor allows you to set a
back System.Drawing.Color with an
Alpha value less than 255. Because standard Win32
controls do not really support true transparency, the default
OnPaintBackground() fakes the painting of the
background for you by getting the parent to paint itself into your
object's System.Drawing.Graphics
surface. While this is OK in simple scenarios, it starts to work
badly when you have nested or overlapping transparent controls. Note
that the technique used is different from (and less effective than)
the XP API DrawThemeParentBackground(), so
interop may offer some additional benefit if you can rely on XP
deployment. The system requires that you also set
UserPaint for transparency.
ResizeRedraw causes the entire control to be
repainted each time it is resized. Note that while this used to be
the default behavior in MFC applications, for .NET, it is turned off
unless you explicitly enable it. This is a good thing, because it
allows your repaint to be much more efficient, only invalidating the
newly exposed rectangles as the control expands. However, if your
painted content is scaled to fit, you should re-enable the feature to
allow you to repaint the whole thing every time.
Finally, there is Opaque. If you enable this, it
implies that you are going to cover every visible pixel in your
control in the OnPaint() function, and that there
is therefore no need to paint the background at all. Be prepared for
a total mess if you fail to cover every pixel!
The second class of styles apply to the input behavior of the object.
If you enable StandardClick, the framework will
automatically handle mouse button clicks, and raise the
Control.Click event for you. If you set
StandardDoubleClick as well, it will raise
Control.DoubleClick too.
Similar to UserPaint, enabling
UserMouse lets the framework know you will be
dealing with the mouse handling, rather than wrapping a Win32 control
that does that work for you.
The remaining styles are a mixed bag of other bits and pieces.
The Selectable style can be enabled to indicate
that the control can receive the focus, and
ContainerControl indicates the object may act as
the parent to other controls (like a GroupBox, for
example). Two styles, FixedWidth and
FixedHeight, indicate that you cannot resize the
control in one or both of these directions.
Finally, there is the EnableNotifyMessage style.
This causes OnNotifyMessage() to be called for
every WM_XXX message passed to your control. This
allows you to handle the message, but not to change it. Compare this
with the Control.WndProc() method that requires
the
System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode
permission to override it, but gives you considerably greater
opportunity to mess with the messages as they pass through.
public enum ControlStyles {
ContainerControl = 0x00000001,
UserPaint = 0x00000002,
Opaque = 0x00000004,
ResizeRedraw = 0x00000010,
FixedWidth = 0x00000020,
FixedHeight = 0x00000040,
StandardClick = 0x00000100,
Selectable = 0x00000200,
UserMouse = 0x00000400,
SupportsTransparentBackColor = 0x00000800,
StandardDoubleClick = 0x00001000,
AllPaintingInWmPaint = 0x00002000,
CacheText = 0x00004000,
EnableNotifyMessage = 0x00008000,
DoubleBuffer = 0x00010000
}