This documentation is archived and is not being maintained.

ControlDesigner Class

Extends the design mode behavior of a Control.

Namespace:  System.Windows.Forms.Design
Assembly:  System.Design (in System.Design.dll)

'Declaration
Public Class ControlDesigner _
	Inherits ComponentDesigner
'Usage
Dim instance As ControlDesigner

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.

Add a reference to the System.Design assembly to compile the code example.

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 ExampleControlDesigner
        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. 
        ' The DesignOnlyAttribute ensures that the OutlineColor 
        ' property is not serialized by the designer. 
        Protected Overrides Sub PreFilterProperties(ByVal properties As System.Collections.IDictionary)
            Dim pd As PropertyDescriptor = TypeDescriptor.CreateProperty( _
            GetType(ExampleControlDesigner), _
            "OutlineColor", _
            GetType(System.Drawing.Color), _
            New Attribute() {New DesignOnlyAttribute(True)})

            properties.Add("OutlineColor", pd)
        End Sub 
    End Class 

    ' This example control demonstrates the ExampleControlDesigner.
    <DesignerAttribute(GetType(ExampleControlDesigner))> _
     Public Class ExampleControl
        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 (components IsNot Nothing) Then
                    components.Dispose()
                End If 
            End If 
            MyBase.Dispose(disposing)
        End Sub 
    End Class 

End Namespace

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
Show: