Export (0) Print
Expand All

ControlPaint Class

Provides methods used to paint common Windows controls and their elements. This class cannot be inherited.

System.Object
  System.Windows.Forms.ControlPaint

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

public sealed class ControlPaint

The ControlPaint type exposes the following members.

  NameDescription
Public propertyStatic memberContrastControlDarkGets the color to use as the ControlDark color.
Top

  NameDescription
Public methodStatic memberCreateHBitmap16BitCreates a 16-bit color bitmap.
Public methodStatic memberCreateHBitmapColorMaskCreates a Win32 HBITMAP out of the image.
Public methodStatic memberCreateHBitmapTransparencyMaskCreates a color mask for the specified bitmap that indicates which color should be displayed as transparent.
Public methodStatic memberDark(Color)Creates a new dark color object for the control from the specified color.
Public methodStatic memberDark(Color, Single)Creates a new dark color object for the control from the specified color and darkens it by the specified percentage.
Public methodStatic memberDarkDarkCreates a new dark color object for the control from the specified color.
Public methodStatic memberDrawBorder(Graphics, Rectangle, Color, ButtonBorderStyle)Draws a border with the specified style and color, on the specified graphics surface, and within the specified bounds on a button-style control.
Public methodStatic memberDrawBorder(Graphics, Rectangle, Color, Int32, ButtonBorderStyle, Color, Int32, ButtonBorderStyle, Color, Int32, ButtonBorderStyle, Color, Int32, ButtonBorderStyle)Draws a border on a button-style control with the specified styles, colors, and border widths; on the specified graphics surface; and within the specified bounds.
Public methodStatic memberDrawBorder3D(Graphics, Rectangle)Draws a three-dimensional style border on the specified graphics surface and within the specified bounds on a control.
Public methodStatic memberDrawBorder3D(Graphics, Rectangle, Border3DStyle)Draws a three-dimensional style border with the specified style, on the specified graphics surface, and within the specified bounds on a control.
Public methodStatic memberDrawBorder3D(Graphics, Rectangle, Border3DStyle, Border3DSide)Draws a three-dimensional style border with the specified style, on the specified graphics surface and sides, and within the specified bounds on a control.
Public methodStatic memberDrawBorder3D(Graphics, Int32, Int32, Int32, Int32)Draws a three-dimensional style border on the specified graphics surface and within the specified bounds on a control.
Public methodStatic memberDrawBorder3D(Graphics, Int32, Int32, Int32, Int32, Border3DStyle)Draws a three-dimensional style border with the specified style, on the specified graphics surface, and within the specified bounds on a control.
Public methodStatic memberDrawBorder3D(Graphics, Int32, Int32, Int32, Int32, Border3DStyle, Border3DSide)Draws a three-dimensional style border with the specified style, on the specified graphics surface and side, and within the specified bounds on a control.
Public methodStatic memberDrawButton(Graphics, Rectangle, ButtonState)Draws a button control in the specified state, on the specified graphics surface, and within the specified bounds.
Public methodStatic memberDrawButton(Graphics, Int32, Int32, Int32, Int32, ButtonState)Draws a button control in the specified state, on the specified graphics surface, and within the specified bounds.
Public methodStatic memberDrawCaptionButton(Graphics, Rectangle, CaptionButton, ButtonState)Draws the specified caption button control in the specified state, on the specified graphics surface, and within the specified bounds.
Public methodStatic memberDrawCaptionButton(Graphics, Int32, Int32, Int32, Int32, CaptionButton, ButtonState)Draws the specified caption button control in the specified state, on the specified graphics surface, and within the specified bounds.
Public methodStatic memberDrawCheckBox(Graphics, Rectangle, ButtonState)Draws a check box control in the specified state, on the specified graphics surface, and within the specified bounds.
Public methodStatic memberDrawCheckBox(Graphics, Int32, Int32, Int32, Int32, ButtonState)Draws a check box control in the specified state, on the specified graphics surface, and within the specified bounds.
Public methodStatic memberDrawComboButton(Graphics, Rectangle, ButtonState)Draws a drop-down button on a combo box control in the specified state, on the specified graphics surface, and within the specified bounds.
Public methodStatic memberDrawComboButton(Graphics, Int32, Int32, Int32, Int32, ButtonState)Draws a drop-down button on a combo box control in the specified state, on the specified graphics surface, and within the specified bounds.
Public methodStatic memberDrawContainerGrabHandleDraws a container control grab handle glyph on the specified graphics surface and within the specified bounds.
Public methodStatic memberDrawFocusRectangle(Graphics, Rectangle)Draws a focus rectangle on the specified graphics surface and within the specified bounds.
Public methodStatic memberDrawFocusRectangle(Graphics, Rectangle, Color, Color)Draws a focus rectangle on the specified graphics surface and within the specified bounds.
Public methodStatic memberDrawGrabHandleDraws a standard selection grab handle glyph on the specified graphics surface, within the specified bounds, and in the specified state and style.
Public methodStatic memberDrawGridDraws a grid of one-pixel dots with the specified spacing, within the specified bounds, on the specified graphics surface, and in the specified color.
Public methodStatic memberDrawImageDisabledDraws the specified image in a disabled state.
Public methodStatic memberDrawLockedFrameDraws a locked selection frame on the screen within the specified bounds and on the specified graphics surface. Specifies whether to draw the frame with the primary selected colors.
Public methodStatic memberDrawMenuGlyph(Graphics, Rectangle, MenuGlyph)Draws the specified menu glyph on a menu item control within the specified bounds and on the specified surface.
Public methodStatic memberDrawMenuGlyph(Graphics, Rectangle, MenuGlyph, Color, Color)Draws the specified menu glyph on a menu item control within the specified bounds and on the specified surface, replacing White with the color specified in the backColor parameter and replacing Black with the color specified in the foreColor parameter.
Public methodStatic memberDrawMenuGlyph(Graphics, Int32, Int32, Int32, Int32, MenuGlyph)Draws the specified menu glyph on a menu item control with the specified bounds and on the specified surface.
Public methodStatic memberDrawMenuGlyph(Graphics, Int32, Int32, Int32, Int32, MenuGlyph, Color, Color)Draws the specified menu glyph on a menu item control within the specified coordinates, height, and width on the specified surface, replacing White with the color specified in the backColor parameter and replacing Black with the color specified in the foreColor parameter.
Public methodStatic memberDrawMixedCheckBox(Graphics, Rectangle, ButtonState)Draws a three-state check box control in the specified state, on the specified graphics surface, and within the specified bounds.
Public methodStatic memberDrawMixedCheckBox(Graphics, Int32, Int32, Int32, Int32, ButtonState)Draws a three-state check box control in the specified state, on the specified graphics surface, and within the specified bounds.
Public methodStatic memberDrawRadioButton(Graphics, Rectangle, ButtonState)Draws a radio button control in the specified state, on the specified graphics surface, and within the specified bounds.
Public methodStatic memberDrawRadioButton(Graphics, Int32, Int32, Int32, Int32, ButtonState)Draws a radio button control in the specified state, on the specified graphics surface, and within the specified bounds.
Public methodStatic memberDrawReversibleFrameDraws a reversible frame on the screen within the specified bounds, with the specified background color, and in the specified state.
Public methodStatic memberDrawReversibleLineDraws a reversible line on the screen within the specified starting and ending points and with the specified background color.
Public methodStatic memberDrawScrollButton(Graphics, Rectangle, ScrollButton, ButtonState)Draws the specified scroll button on a scroll bar control in the specified state, on the specified graphics surface, and within the specified bounds.
Public methodStatic memberDrawScrollButton(Graphics, Int32, Int32, Int32, Int32, ScrollButton, ButtonState)Draws the specified scroll button on a scroll bar control in the specified state, on the specified graphics surface, and within the specified bounds.
Public methodStatic memberDrawSelectionFrameDraws a standard selection frame in the specified state, on the specified graphics surface, with the specified inner and outer dimensions, and with the specified background color.
Public methodStatic memberDrawSizeGrip(Graphics, Color, Rectangle)Draws a size grip on a form with the specified bounds and background color and on the specified graphics surface.
Public methodStatic memberDrawSizeGrip(Graphics, Color, Int32, Int32, Int32, Int32)Draws a size grip on a form with the specified bounds and background color and on the specified graphics surface.
Public methodStatic memberDrawStringDisabled(Graphics, String, Font, Color, RectangleF, StringFormat)Draws the specified string in a disabled state on the specified graphics surface; within the specified bounds; and in the specified font, color, and format.
Public methodStatic memberDrawStringDisabled(IDeviceContext, String, Font, Color, Rectangle, TextFormatFlags)Draws the specified string in a disabled state on the specified graphics surface, within the specified bounds, and in the specified font, color, and format, using the specified GDI-based TextRenderer.
Public methodStatic memberDrawVisualStyleBorderDraws a border in the style appropriate for disabled items.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodStatic memberFillReversibleRectangleDraws a filled, reversible rectangle on the screen.
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodStatic memberLight(Color)Creates a new light color object for the control from the specified color.
Public methodStatic memberLight(Color, Single)Creates a new light color object for the control from the specified color and lightens it by the specified percentage.
Public methodStatic memberLightLightCreates a new light color object for the control from the specified color.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

The methods contained in the ControlPaint class enable you to draw your own controls or elements of controls. You can control the drawing of your own controls if the UserPaint bit is set to true for the control. You can get or set the style bits by calling the GetStyle or SetStyle methods. You can set multiple style bits for any control. The ControlStyles enumeration members can be combined with bitwise operations.

The following code example uses one of the ControlPaint constructors to draw a flat Button control.

using System;
using System.Drawing;
using System.Windows.Forms;

public class Form1 : Form
{
      private Button button1 = new Button();
      private Button button2 = new Button();


    [STAThread]
    static void Main() 
    {
        Application.Run(new Form1());
    }


    public Form1(){
        this.button2.Location = new Point(0, button1.Height + 10);
        this.Click += new EventHandler(this.button2_Click);
        this.Controls.Add(this.button1);
        this.Controls.Add(this.button2);
    }

    private void button2_Click(object sender, System.EventArgs e)
    {
        // Draws a flat button on button1.
        ControlPaint.DrawButton(
        System.Drawing.Graphics.FromHwnd(button1.Handle),0,0,button1.Width,button1.Height,
                ButtonState.Flat);
    }
}

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft