ControlPaint 類別

定義

提供用來繪製通用 Windows 控制項和其元件的方法。Provides methods used to paint common Windows controls and their elements. 無法繼承這個類別。This class cannot be inherited.

public ref class ControlPaint sealed
public sealed class ControlPaint
type ControlPaint = class
Public NotInheritable Class ControlPaint
繼承
ControlPaint

範例

下列程式碼範例會使用其中一個 ControlPaint 的構造函式來繪製一般 Button 控制項。The following code example uses one of the ControlPaint constructors to draw a flat Button control.

#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
public ref class Form1: public Form
{
private:
   Button^ button1;
   Button^ button2;

public:
   Form1()
   {
      button1 = gcnew Button;
      button2 = gcnew Button;
      this->button2->Location = Point(0,button1->Height + 10);
      this->Click += gcnew EventHandler( this, &Form1::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 );
   }

};


[STAThread]
void main()
{
   Application::Run( gcnew Form1 );
}

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()
    {
        _button2.Location = new Point(0, _button1.Height + 10);
        this.Click += Button2_Click;
        this.Controls.Add(_button1);
        this.Controls.Add(_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);
    }

}
Imports System.Drawing
Imports System.Windows.Forms

    Public Class Form1
        Inherits System.Windows.Forms.Form

        Private button1 As System.Windows.Forms.Button = New Button
        Private button2 As System.Windows.Forms.Button = New Button

        <System.STAThreadAttribute()>  _
        Public Shared Sub Main()
            System.Windows.Forms.Application.Run(New Form1)
        End Sub

        Public Sub New()
            Me.button2.Location = New Point(0, button1.Height + 10)
            AddHandler Me.button2.Click, AddressOf Me.button2_Click
            Me.Controls.Add(Me.button1)
            Me.Controls.Add(Me.button2)
        End Sub

        Private Sub button2_Click(sender As Object, e As System.EventArgs)
            ' Draws a flat button on button1.
            ControlPaint.DrawButton(System.Drawing.Graphics.FromHwnd(button1.Handle), 0, 0, button1.Width, button1.Height, ButtonState.Flat)
        End Sub
End Class

備註

ControlPaint 類別中包含的方法可讓您繪製自己的控制項或控制項的元素。The methods contained in the ControlPaint class enable you to draw your own controls or elements of controls. 如果 UserPaint 位設為控制項的 true,您可以控制自己控制項的繪製。You can control the drawing of your own controls if the UserPaint bit is set to true for the control. 您可以藉由呼叫 GetStyleSetStyle 方法來取得或設定樣式位。You can get or set the style bits by calling the GetStyle or SetStyle methods. 您可以為任何控制項設定多個樣式位。You can set multiple style bits for any control. ControlStyles 列舉成員可以與位運算結合。The ControlStyles enumeration members can be combined with bitwise operations.

屬性

ContrastControlDark

取得當做 ControlDark 色彩使用的色彩。Gets the color to use as the ControlDark color.

方法

CreateHBitmap16Bit(Bitmap, Color)

建立 16 位元色彩的點陣圖。Creates a 16-bit color bitmap.

CreateHBitmapColorMask(Bitmap, IntPtr)

在影像外部建立 Win32 HBITMAPCreates a Win32 HBITMAP out of the image.

CreateHBitmapTransparencyMask(Bitmap)

為指定的點陣圖建立色彩遮罩,表示哪些色彩應顯示為透明。Creates a color mask for the specified bitmap that indicates which color should be displayed as transparent.

Dark(Color)

從指定的色彩為控制項建立新的深色物件。Creates a new dark color object for the control from the specified color.

Dark(Color, Single)

從指定的色彩為控制項建立新的深色物件,並使用指定的百分比暗化這個物件。Creates a new dark color object for the control from the specified color and darkens it by the specified percentage.

DarkDark(Color)

從指定的色彩為控制項建立新的深色物件。Creates a new dark color object for the control from the specified color.

DrawBorder(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.

DrawBorder(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.

DrawBorder3D(Graphics, Int32, Int32, Int32, Int32)

在指定的圖形表層和控制項的指定範圍內,繪製 3D 樣式框線。Draws a three-dimensional style border on the specified graphics surface and within the specified bounds on a control.

DrawBorder3D(Graphics, Int32, Int32, Int32, Int32, Border3DStyle)

使用指定的樣式,在指定的圖形表層和控制項的指定範圍內繪製 3D 樣式框線。Draws a three-dimensional style border with the specified style, on the specified graphics surface, and within the specified bounds on a control.

DrawBorder3D(Graphics, Int32, Int32, Int32, Int32, Border3DStyle, Border3DSide)

使用指定的樣式、在指定的圖形表層和側邊,和控制項的指定範圍內繪製 3D 樣式框線。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.

DrawBorder3D(Graphics, Rectangle)

在指定的圖形表層和控制項的指定範圍內,繪製 3D 樣式框線。Draws a three-dimensional style border on the specified graphics surface and within the specified bounds on a control.

DrawBorder3D(Graphics, Rectangle, Border3DStyle)

使用指定的樣式,在指定的圖形表層和控制項的指定範圍內繪製 3D 樣式框線。Draws a three-dimensional style border with the specified style, on the specified graphics surface, and within the specified bounds on a control.

DrawBorder3D(Graphics, Rectangle, Border3DStyle, Border3DSide)

使用指定的樣式、在指定的圖形表層和側邊,和控制項的指定範圍內繪製 3D 樣式框線。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.

DrawButton(Graphics, Int32, Int32, Int32, Int32, ButtonState)

在指定的圖形表層和指定的範圍內,繪製指定狀態的按鈕控制項。Draws a button control in the specified state, on the specified graphics surface, and within the specified bounds.

DrawButton(Graphics, Rectangle, ButtonState)

在指定的圖形表層和指定的範圍內,繪製指定狀態的按鈕控制項。Draws a button control in the specified state, on the specified graphics surface, and within the specified bounds.

DrawCaptionButton(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.

DrawCaptionButton(Graphics, Rectangle, CaptionButton, ButtonState)

在指定的圖形表層和指定的範圍內,繪製指定狀態的指定標題按鈕控制項。Draws the specified caption button control in the specified state, on the specified graphics surface, and within the specified bounds.

DrawCheckBox(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.

DrawCheckBox(Graphics, Rectangle, ButtonState)

在指定的圖形表層和指定的範圍內,繪製指定狀態的核取方塊控制項。Draws a check box control in the specified state, on the specified graphics surface, and within the specified bounds.

DrawComboButton(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.

DrawComboButton(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.

DrawContainerGrabHandle(Graphics, Rectangle)

在指定的圖形表層和指定的範圍內,繪製容器控制項抓取控點圖像 (Glyph)。Draws a container control grab handle glyph on the specified graphics surface and within the specified bounds.

DrawFocusRectangle(Graphics, Rectangle)

在指定的圖形表層和指定的範圍內,繪製焦點矩形。Draws a focus rectangle on the specified graphics surface and within the specified bounds.

DrawFocusRectangle(Graphics, Rectangle, Color, Color)

在指定的圖形表層和指定的範圍內,繪製焦點矩形。Draws a focus rectangle on the specified graphics surface and within the specified bounds.

DrawGrabHandle(Graphics, Rectangle, Boolean, Boolean)

在指定的圖形表層和指定的範圍內,繪製指定狀態和樣式的標準選取抓取控點圖像。Draws a standard selection grab handle glyph on the specified graphics surface, within the specified bounds, and in the specified state and style.

DrawGrid(Graphics, Rectangle, Size, Color)

使用指定的色彩,在指定的範圍內和指定的圖形表層上繪製格線 (其指定間距為一個像素點)。Draws a grid of one-pixel dots with the specified spacing, within the specified bounds, on the specified graphics surface, and in the specified color.

DrawImageDisabled(Graphics, Image, Int32, Int32, Color)

繪製停用狀況的指定影像。Draws the specified image in a disabled state.

DrawLockedFrame(Graphics, Rectangle, Boolean)

在指定範圍的螢幕內和指定的圖形表層上,繪製鎖定的選取框架 (Frame)。Draws 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.

DrawMenuGlyph(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.

DrawMenuGlyph(Graphics, Int32, Int32, Int32, Int32, MenuGlyph, Color, Color)

在指定的座標、高度和寬度以及指定的介面上,於功能表項目控制項上繪製指定的功能表圖像,並使用 White 參數中指定的色彩取代 backColor 而使用 Black 參數中指定的色彩取代 foreColorDraws 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.

DrawMenuGlyph(Graphics, Rectangle, MenuGlyph)

在指定的範圍和指定的表層中,在功能表項目控制項上繪製指定的功能表圖像。Draws the specified menu glyph on a menu item control within the specified bounds and on the specified surface.

DrawMenuGlyph(Graphics, Rectangle, MenuGlyph, Color, Color)

在指定的範圍和指定的介面上,於功能表項目控制項上繪製指定的功能表圖像,並使用 White 參數中指定的色彩取代 backColor 而使用 Black 參數中指定的色彩取代 foreColorDraws 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.

DrawMixedCheckBox(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.

DrawMixedCheckBox(Graphics, Rectangle, ButtonState)

在指定的圖形表層和指定的範圍內,繪製指定狀態的三態核取方塊控制項。Draws a three-state check box control in the specified state, on the specified graphics surface, and within the specified bounds.

DrawRadioButton(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.

DrawRadioButton(Graphics, Rectangle, ButtonState)

在指定的圖形表層和指定的範圍內,繪製指定狀態的選項按鈕控制項。Draws a radio button control in the specified state, on the specified graphics surface, and within the specified bounds.

DrawReversibleFrame(Rectangle, Color, FrameStyle)

使用指定的背景色彩,在指定範圍的螢幕內繪製指定狀態的可反轉框架。Draws a reversible frame on the screen within the specified bounds, with the specified background color, and in the specified state.

DrawReversibleLine(Point, Point, Color)

在指定起點和結束點範圍的螢幕內,使用指定的背景色彩繪製可反轉的線。Draws a reversible line on the screen within the specified starting and ending points and with the specified background color.

DrawScrollButton(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.

DrawScrollButton(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.

DrawSelectionFrame(Graphics, Boolean, Rectangle, Rectangle, Color)

在指定的圖形表層上,繪製指定狀態的標準選取框架,其具有指定內部和外部大小和指定的背景色彩。Draws 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.

DrawSizeGrip(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.

DrawSizeGrip(Graphics, Color, Rectangle)

在指定的圖形表層和指定的範圍和背景色彩中,於表單上繪製調整大小的底框。Draws a size grip on a form with the specified bounds and background color and on the specified graphics surface.

DrawStringDisabled(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.

DrawStringDisabled(IDeviceContext, String, Font, Color, Rectangle, TextFormatFlags)

使用指定的 GDI 式 TextRenderer 及指定的字型、色彩和格式,在指定的圖形介面和指定的範圍內,繪製停用狀態的指定字串。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.

DrawVisualStyleBorder(Graphics, Rectangle)

使用適當的樣式繪製停用項目的框線。Draws a border in the style appropriate for disabled items.

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
FillReversibleRectangle(Rectangle, Color)

在螢幕上繪製填滿、可反轉的矩形。Draws a filled, reversible rectangle on the screen.

GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
Light(Color)

從指定的色彩為控制項建立新的淺色物件。Creates a new light color object for the control from the specified color.

Light(Color, Single)

從指定的色彩為控制項建立新的淺色物件,並使用指定的百分比淡化該物件。Creates a new light color object for the control from the specified color and lightens it by the specified percentage.

LightLight(Color)

從指定的色彩為控制項建立新的淺色物件。Creates a new light color object for the control from the specified color.

MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

適用於

另請參閱