ControlPaint 類別

定義

提供用來繪製通用 Windows 控制項和其元件的方法。 此類別無法獲得繼承。

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

範例

下列程式碼範例會使用其中 ControlPaint 一個建構函式來繪製一般 Button 控制項。

#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 方法可讓您繪製自己的控制項或控制項專案。 如果 UserPaint 控制項的位設定 true 為 ,您可以控制自己的控制項繪圖。 您可以藉由呼叫 GetStyleSetStyle 方法來取得或設定樣式位。 您可以為任何控制項設定多個樣式位。 列舉 ControlStyles 成員可以與位運算結合。

屬性

ContrastControlDark

取得當做 ControlDark 色彩使用的色彩。

方法

CreateHBitmap16Bit(Bitmap, Color)

建立 16 位元色彩的點陣圖。

CreateHBitmapColorMask(Bitmap, IntPtr)

在影像外部建立 Win32 HBITMAP

CreateHBitmapTransparencyMask(Bitmap)

為指定的點陣圖建立色彩遮罩,表示哪些色彩應顯示為透明。

Dark(Color)

從指定的色彩為控制項建立新的深色物件。

Dark(Color, Single)

從指定的色彩為控制項建立新的深色物件,並使用指定的百分比暗化這個物件。

DarkDark(Color)

從指定的色彩為控制項建立新的深色物件。

DrawBorder(Graphics, Rectangle, Color, ButtonBorderStyle)

使用指定的樣式和色彩,在指定的圖形表層和按鈕樣式控制項的指定範圍內繪製框線。

DrawBorder(Graphics, Rectangle, Color, Int32, ButtonBorderStyle, Color, Int32, ButtonBorderStyle, Color, Int32, ButtonBorderStyle, Color, Int32, ButtonBorderStyle)

使用指定的樣式、色彩和框線寬度,在指定的圖形介面和指定的範圍內,於按鈕樣式控制項上繪製框線。

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

在指定的圖形表層和控制項的指定範圍內,繪製 3D 樣式框線。

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

使用指定的樣式,在指定的圖形表層和控制項的指定範圍內繪製 3D 樣式框線。

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

使用指定的樣式、在指定的圖形表層和側邊,和控制項的指定範圍內繪製 3D 樣式框線。

DrawBorder3D(Graphics, Rectangle)

在指定的圖形表層和控制項的指定範圍內,繪製 3D 樣式框線。

DrawBorder3D(Graphics, Rectangle, Border3DStyle)

使用指定的樣式,在指定的圖形表層和控制項的指定範圍內繪製 3D 樣式框線。

DrawBorder3D(Graphics, Rectangle, Border3DStyle, Border3DSide)

使用指定的樣式、在指定的圖形表層和側邊,和控制項的指定範圍內繪製 3D 樣式框線。

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

在指定的圖形表層和指定的範圍內,繪製指定狀態的按鈕控制項。

DrawButton(Graphics, Rectangle, ButtonState)

在指定的圖形表層和指定的範圍內,繪製指定狀態的按鈕控制項。

DrawCaptionButton(Graphics, Int32, Int32, Int32, Int32, CaptionButton, ButtonState)

在指定的圖形表層和指定的範圍內,繪製指定狀態的指定標題按鈕控制項。

DrawCaptionButton(Graphics, Rectangle, CaptionButton, ButtonState)

在指定的圖形表層和指定的範圍內,繪製指定狀態的指定標題按鈕控制項。

DrawCheckBox(Graphics, Int32, Int32, Int32, Int32, ButtonState)

在指定的圖形表層和指定的範圍內,繪製指定狀態的核取方塊控制項。

DrawCheckBox(Graphics, Rectangle, ButtonState)

在指定的圖形表層和指定的範圍內,繪製指定狀態的核取方塊控制項。

DrawComboButton(Graphics, Int32, Int32, Int32, Int32, ButtonState)

在指定的圖形表層和指定的範圍內,在下拉式方塊控制項上繪製指定狀態的下拉式按鈕。

DrawComboButton(Graphics, Rectangle, ButtonState)

在指定的圖形表層和指定的範圍內,在下拉式方塊控制項上繪製指定狀態的下拉式按鈕。

DrawContainerGrabHandle(Graphics, Rectangle)

在指定的圖形表層和指定的範圍內,繪製容器控制項抓取控點圖像 (Glyph)。

DrawFocusRectangle(Graphics, Rectangle)

在指定的圖形表層和指定的範圍內,繪製焦點矩形。

DrawFocusRectangle(Graphics, Rectangle, Color, Color)

在指定的圖形表層和指定的範圍內,繪製焦點矩形。

DrawGrabHandle(Graphics, Rectangle, Boolean, Boolean)

在指定的圖形表層和指定的範圍內,繪製指定狀態和樣式的標準選取抓取控點圖像。

DrawGrid(Graphics, Rectangle, Size, Color)

使用指定的色彩,在指定的範圍內和指定的圖形表層上繪製格線 (其指定間距為一個像素點)。

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

繪製停用狀況的指定影像。

DrawLockedFrame(Graphics, Rectangle, Boolean)

在指定範圍的螢幕內和指定的圖形表層上,繪製鎖定的選取框架 (Frame)。 指定是否使用主要選取色彩繪製框架。

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

在指定的範圍和指定的表層中,在功能表項目控制項上繪製指定的功能表圖像。

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

在指定的座標、高度和寬度以及指定的介面上,於功能表項目控制項上繪製指定的功能表圖像,並使用 backColor 參數中指定的色彩取代 White 而使用 foreColor 參數中指定的色彩取代 Black

DrawMenuGlyph(Graphics, Rectangle, MenuGlyph)

在指定的範圍和指定的表層中,在功能表項目控制項上繪製指定的功能表圖像。

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

在指定的範圍和指定的介面上,於功能表項目控制項上繪製指定的功能表圖像,並使用 backColor 參數中指定的色彩取代 White 而使用 foreColor 參數中指定的色彩取代 Black

DrawMixedCheckBox(Graphics, Int32, Int32, Int32, Int32, ButtonState)

在指定的圖形表層和指定的範圍內,繪製指定狀態的三態核取方塊控制項。

DrawMixedCheckBox(Graphics, Rectangle, ButtonState)

在指定的圖形表層和指定的範圍內,繪製指定狀態的三態核取方塊控制項。

DrawRadioButton(Graphics, Int32, Int32, Int32, Int32, ButtonState)

在指定的圖形表層和指定的範圍內,繪製指定狀態的選項按鈕控制項。

DrawRadioButton(Graphics, Rectangle, ButtonState)

在指定的圖形表層和指定的範圍內,繪製指定狀態的選項按鈕控制項。

DrawReversibleFrame(Rectangle, Color, FrameStyle)

使用指定的背景色彩,在指定範圍的螢幕內繪製指定狀態的可反轉框架。

DrawReversibleLine(Point, Point, Color)

在指定起點和結束點範圍的螢幕內,使用指定的背景色彩繪製可反轉的線。

DrawScrollButton(Graphics, Int32, Int32, Int32, Int32, ScrollButton, ButtonState)

在指定的圖形表層和指定的範圍內,於捲軸控制項上繪製指定狀態的指定捲軸按鈕。

DrawScrollButton(Graphics, Rectangle, ScrollButton, ButtonState)

在指定的圖形表層和指定的範圍內,於捲軸控制項上繪製指定狀態的指定捲軸按鈕。

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

在指定的圖形表層上,繪製指定狀態的標準選取框架,其具有指定內部和外部大小和指定的背景色彩。

DrawSizeGrip(Graphics, Color, Int32, Int32, Int32, Int32)

在指定的圖形表層和指定的範圍和背景色彩中,於表單上繪製調整大小的底框。

DrawSizeGrip(Graphics, Color, Rectangle)

在指定的圖形表層和指定的範圍和背景色彩中,於表單上繪製調整大小的底框。

DrawStringDisabled(Graphics, String, Font, Color, RectangleF, StringFormat)

使用指定的字型、色彩和格式,在指定的圖形介面和指定的範圍內,繪製停用狀態的指定字串。

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

使用指定的 GDI 式 TextRenderer 及指定的字型、色彩和格式,在指定的圖形介面和指定的範圍內,繪製停用狀態的指定字串。

DrawVisualStyleBorder(Graphics, Rectangle)

使用適當的樣式繪製停用項目的框線。

FillReversibleRectangle(Rectangle, Color)

在螢幕上繪製填滿、可反轉的矩形。

Light(Color)

從指定的色彩為控制項建立新的淺色物件。

Light(Color, Single)

從指定的色彩為控制項建立新的淺色物件,並使用指定的百分比淡化該物件。

LightLight(Color)

從指定的色彩為控制項建立新的淺色物件。

適用於

另請參閱