Provides methods used to paint common Windows controls and their elements. This class cannot be inherited.
Namespace:
System.Windows.Forms
Assembly:
System.Windows.Forms (in System.Windows.Forms.dll)
Visual Basic (Declaration)
Public NotInheritable Class ControlPaint
Dim instance As ControlPaint
public sealed class ControlPaint
public ref class ControlPaint sealed
public final class ControlPaint
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.
Imports System
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 'button2_Click
End Class
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);
}
}
#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 );
}
System..::.Object
System.Windows.Forms..::.ControlPaint
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Reference