ControlPaint 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
提供用來繪製通用 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
為 ,您可以控制自己的控制項繪圖。 您可以藉由呼叫 GetStyle 或 SetStyle 方法來取得或設定樣式位。 您可以為任何控制項設定多個樣式位。 列舉 ControlStyles 成員可以與位運算結合。
屬性
ContrastControlDark |
取得當做 ControlDark 色彩使用的色彩。 |