ControlDesigner Class
Assembly: System.Design (in system.design.dll)
ControlDesigner provides a base class for designers of components that derive from Control. In addition to the methods and functionality inherited from the ComponentDesigner class, ControlDesigner provides additional methods to support extending and altering the behavior of an associated Control at design time.
You can associate a designer with a type using a DesignerAttribute. For an overview of customizing design time behavior, see Extending Design-Time Support.
The following example ControlDesigner implementation demonstrates handling MouseEnter and MouseLeave events, drawing on a control from designer code, and using part of the IDesignerFilter interface to add a property for the control at design time. The following sample code contains a designer and a sample user control associated with the designer. To build this sample, compile the sample into a class library, add a reference to the library to a Windows Forms project, add the control to the Toolbox, and add an instance of the control to your form. When you point to the control, the inner outline of the perimeter of the control is highlighted, and the color used to draw the outline corresponds to the OutlineColor property that the designer has added to the properties listed for the control.
Imports System Imports System.ComponentModel Imports System.ComponentModel.Design Imports System.Collections Imports System.Drawing Imports System.Windows.Forms Imports System.Windows.Forms.Design Namespace ControlDesignerExample _ ' ExampleControlDesigner is an example control designer that ' demonstrates basic functions of a ControlDesigner. <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _ Public Class TestControlDesigner Inherits System.Windows.Forms.Design.ControlDesigner ' This boolean state reflects whether the mouse is over the control. Private mouseover As Boolean = False ' This color is a private field for the OutlineColor property. Private lineColor As Color = Color.White ' This color is used to outline the control when the mouse is ' over the control. Public Property OutlineColor() As Color Get Return lineColor End Get Set(ByVal Value As Color) lineColor = Value End Set End Property Public Sub New() End Sub ' Sets a value and refreshes the control's display when the ' mouse position enters the area of the control. Protected Overrides Sub OnMouseEnter() Me.mouseover = True Me.Control.Refresh() End Sub ' Sets a value and refreshes the control's display when the ' mouse position enters the area of the control. Protected Overrides Sub OnMouseLeave() Me.mouseover = False Me.Control.Refresh() End Sub ' Draws an outline around the control when the mouse is ' over the control. Protected Overrides Sub OnPaintAdornments(ByVal pe As System.Windows.Forms.PaintEventArgs) If Me.mouseover Then pe.Graphics.DrawRectangle(New Pen(New SolidBrush(Me.lineColor), 6), 0, 0, Me.Control.Size.Width, Me.Control.Size.Height) End If End Sub ' Adds a property to this designer's control at design time ' that indicates the outline color to use. Protected Overrides Sub PreFilterProperties(ByVal properties As System.Collections.IDictionary) properties.Add("OutlineColor", TypeDescriptor.CreateProperty(GetType(TestControlDesigner), "OutlineColor", GetType(System.Drawing.Color), Nothing)) End Sub End Class ' This example control demonstrates the ExampleControlDesigner. <DesignerAttribute(GetType(TestControlDesigner))> _ Public Class TestControl Inherits System.Windows.Forms.UserControl Private components As System.ComponentModel.Container = Nothing Public Sub New() components = New System.ComponentModel.Container() End Sub Protected Overloads Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub End Class End Namespace
System.ComponentModel.Design.ComponentDesigner
System.Windows.Forms.Design.ControlDesigner
System.Windows.Forms.Design.ParentControlDesigner
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.