Export (0) Print
Expand All

ControlDesigner Class

Extends the design mode behavior of a Control.

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

public class ControlDesigner : ComponentDesigner
public class ControlDesigner extends ComponentDesigner
public class ControlDesigner extends ComponentDesigner

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.

using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace ControlDesignerExample
{
    // ExampleControlDesigner is an example control designer that 
    // demonstrates basic functions of a ControlDesigner.
    [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")] 
    public class ExampleControlDesigner  : System.Windows.Forms.Design.ControlDesigner
    {
        // This boolean state reflects whether the mouse is over the control.
        private bool mouseover = false;
        // This color is a private field for the OutlineColor property.
        private Color lineColor = Color.White;

        // This color is used to outline the control when the mouse is 
        // over the control.
        public Color OutlineColor
        {
            get
            {
                return lineColor;
            }
            set
            {
                lineColor = value;
            }
        }

        public ExampleControlDesigner()
        {
        }

        // Sets a value and refreshes the control's display when the 
        // mouse position enters the area of the control.
        protected override void OnMouseEnter()
        {
            this.mouseover = true;
            this.Control.Refresh();
        }	

        // Sets a value and refreshes the control's display when the 
        // mouse position enters the area of the control.		
        protected override void OnMouseLeave()
        {
            this.mouseover = false;			
            this.Control.Refresh();
        }		
        
        // Draws an outline around the control when the mouse is 
        // over the control.	
        protected override void OnPaintAdornments(System.Windows.Forms.PaintEventArgs pe)
        {
            if(this.mouseover)
                pe.Graphics.DrawRectangle(new Pen(new SolidBrush(this.lineColor), 6), 0, 0, this.Control.Size.Width, this.Control.Size.Height);		
        }

        // Adds a property to this designer's control at design time 
        // that indicates the outline color to use.
        protected override void PreFilterProperties(System.Collections.IDictionary properties)
        {
            properties.Add("OutlineColor", TypeDescriptor.CreateProperty(typeof(ExampleControlDesigner), "OutlineColor", typeof(System.Drawing.Color), null));
        }
    }

    // This example control demonstrates the ExampleControlDesigner.
    [DesignerAttribute(typeof(ExampleControlDesigner))]
    public class ExampleControl : System.Windows.Forms.UserControl
    {		
        private System.ComponentModel.Container components = null;

        public ExampleControl()
        {
            components = new System.ComponentModel.Container();
        }

        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if( components != null )
                components.Dispose();
            }
            base.Dispose( disposing );
        }
    }
}

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 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.

.NET Framework

Supported in: 2.0, 1.1, 1.0
Show:
© 2014 Microsoft