ControlDesigner 类

定义

扩展 Control 的设计模式行为。Extends the design mode behavior of a Control.

public ref class ControlDesigner : System::ComponentModel::Design::ComponentDesigner
public class ControlDesigner : System.ComponentModel.Design.ComponentDesigner
type ControlDesigner = class
    inherit ComponentDesigner
Public Class ControlDesigner
Inherits ComponentDesigner
继承
ControlDesigner
派生

示例

下面的示例 ControlDesigner 实现演示了如何处理 MouseEnterMouseLeave 事件、从设计器代码中的控件绘制,以及如何在设计时使用 IDesignerFilter 接口的一部分添加控件的属性。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. 若要生成此示例,请将示例编译为类库,将对库的引用添加到 Windows 窗体项目中,将控件添加到 "工具箱",然后将控件的实例添加到窗体。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. 指向控件时,将突出显示控件外围的内部轮廓,而用于绘制轮廓的颜色对应于设计器已添加到为控件列出的属性的 OutlineColor 属性。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.

添加对 System.web 程序集的引用以编译代码示例。Add a reference to the System.Design assembly to compile the code example.

using namespace System;
using namespace System::ComponentModel;
using namespace System::ComponentModel::Design;
using namespace System::Collections;
using namespace System::Drawing;
using namespace System::Windows::Forms;
using namespace System::Windows::Forms::Design;
using namespace System::Security::Permissions;

   public ref class TestControlDesigner: public System::Windows::Forms::Design::ControlDesigner
   {
   private:
      bool mouseover;
      Color lineColor;

   public:

      property Color OutlineColor 
      {
         Color get()
         {
            return lineColor;
         }

         void set( Color value )
         {
            lineColor = value;
         }

      }
      TestControlDesigner()
      {
         mouseover = false;
         lineColor = Color::White;
      }

   protected:
      virtual void OnMouseEnter() override
      {
         this->mouseover = true;
         this->Control->Refresh();
      }

      virtual void OnMouseLeave() override
      {
         this->mouseover = false;
         this->Control->Refresh();
      }

      virtual void OnPaintAdornments( System::Windows::Forms::PaintEventArgs^ pe ) override
      {
         if ( this->mouseover )
                  pe->Graphics->DrawRectangle( gcnew Pen( gcnew SolidBrush( this->lineColor ),6 ), 0, 0, this->Control->Size.Width, this->Control->Size.Height );
      }

   protected:
      [ReflectionPermission(SecurityAction::Demand, Flags=ReflectionPermissionFlag::MemberAccess)]
      virtual void PreFilterProperties( System::Collections::IDictionary^ properties ) override
      {
         properties->Add( "OutlineColor", TypeDescriptor::CreateProperty( TestControlDesigner::typeid, "OutlineColor", System::Drawing::Color::typeid, nullptr ) );
      }
   };

   [DesignerAttribute(TestControlDesigner::typeid)]
   public ref class TestControl: public System::Windows::Forms::UserControl
   {
   private:
      System::ComponentModel::Container^ components;

   public:
      TestControl()
      {
         components = gcnew System::ComponentModel::Container;
      }

   protected:
      ~TestControl()
      {
         if ( components != nullptr )
         {
            delete components;
         }
      }
   };
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. 
        // The DesignOnlyAttribute ensures that the OutlineColor
        // property is not serialized by the designer.
        protected override void PreFilterProperties(System.Collections.IDictionary properties)
        {
            PropertyDescriptor pd = TypeDescriptor.CreateProperty(
                typeof(ExampleControlDesigner), 
                "OutlineColor",
                typeof(System.Drawing.Color),
                new Attribute[] { new DesignOnlyAttribute(true) });

            properties.Add("OutlineColor", pd);
        }
    }

    // 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 );
        }
    }
}
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

注解

ControlDesigner 提供派生自 Control的组件设计器的基类。ControlDesigner provides a base class for designers of components that derive from Control. 除了从 ComponentDesigner 类继承的方法和功能之外,ControlDesigner 提供其他方法来支持在设计时扩展和更改关联 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.

您可以使用 DesignerAttribute将设计器与类型相关联。You can associate a designer with a type using a DesignerAttribute. 有关自定义设计时行为的概述,请参阅扩展设计时支持For an overview of customizing design time behavior, see Extending Design-Time Support.

构造函数

ControlDesigner()

初始化 ControlDesigner 类的新实例。Initializes a new instance of the ControlDesigner class.

字段

accessibilityObj

为设计器指定可访问对象。Specifies the accessibility object for the designer.

InvalidPoint

定义一个本地 Point,它表示无效 Point 的值。Defines a local Point that represents the values of an invalid Point.

属性

AccessibilityObject

获取分配给该控件的 AccessibleObjectGets the AccessibleObject assigned to the control.

ActionLists

获取与设计器相关联的组件所支持的设计时操作列表。Gets the design-time action lists supported by the component associated with the designer.

(继承自 ComponentDesigner)
AssociatedComponents

获取与设计器所管理的组件关联的组件集合。Gets the collection of components associated with the component managed by the designer.

AutoResizeHandles

获取或设置一个值,该值指示调整手柄的分配是否取决于 AutoSize 属性的值。Gets or sets a value indicating whether resize handle allocation depends on the value of the AutoSize property.

BehaviorService

从设计环境获取 BehaviorServiceGets the BehaviorService from the design environment.

Component

获取此设计器正在设计的组件。Gets the component this designer is designing.

(继承自 ComponentDesigner)
Control

获取设计器正在设计的控件。Gets the control that the designer is designing.

EnableDragRect

获取一个值,该值指示是否可以在该设计器组件上绘制拖动矩形。Gets a value indicating whether drag rectangles can be drawn on this designer component.

InheritanceAttribute

获取设计器的 InheritanceAttributeGets the InheritanceAttribute of the designer.

Inherited

获取一个值,该值指示是否继承此组件。Gets a value indicating whether this component is inherited.

(继承自 ComponentDesigner)
ParentComponent

获取 ControlDesigner 的父组件。Gets the parent component for the ControlDesigner.

ParticipatesWithSnapLines

获取一个值,该值指示在拖动操作期间 ControlDesigner 是否允许按对齐线对齐。Gets a value indicating whether the ControlDesigner will allow snapline alignment during a drag operation.

SelectionRules

获取指示组件的移动功能的选择规则。Gets the selection rules that indicate the movement capabilities of a component.

ShadowProperties

获取重写用户设置的属性值的集合。Gets a collection of property values that override user settings.

(继承自 ComponentDesigner)
SnapLines

获取表示此控件的重要对齐点的 SnapLine 对象的列表。Gets a list of SnapLine objects representing significant alignment points for this control.

Verbs

获取与设计器相关联的组件所支持的设计时谓词。Gets the design-time verbs supported by the component that is associated with the designer.

(继承自 ComponentDesigner)

方法

BaseWndProc(Message)

处理 Windows 消息。Processes Windows messages.

CanBeParentedTo(IDesigner)

指示指定设计器的控件是否可以成为此设计器控件的父级。Indicates if this designer's control can be parented by the control of the specified designer.

DefWndProc(Message)

提供对 Windows 消息的默认处理。Provides default processing for Windows messages.

DisplayError(Exception)

向用户显示有关所指定异常的信息。Displays information about the specified exception to the user.

Dispose()

释放 ComponentDesigner 使用的所有资源。Releases all resources used by the ComponentDesigner.

(继承自 ComponentDesigner)
Dispose(Boolean)

释放 ControlDesigner 使用的非托管资源,并选择性地释放托管资源。Releases the unmanaged resources used by the ControlDesigner and optionally releases the managed resources.

DoDefaultAction()

在源代码文件中为组件的默认事件创建方法签名,并将用户的光标定位到该位置。Creates a method signature in the source code file for the default event on the component and navigates the user's cursor to that location.

(继承自 ComponentDesigner)
EnableDesignMode(Control, String)

启用子控件的设计时功能。Enables design time functionality for a child control.

EnableDragDrop(Boolean)

启用或禁用对正在设计的控件的拖放支持。Enables or disables drag-and-drop support for the control being designed.

Equals(Object)

确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetControlGlyph(GlyphSelectionType)

返回表示此控件的边界的 ControlBodyGlyphReturns a ControlBodyGlyph representing the bounds of this control.

GetGlyphs(GlyphSelectionType)

获取一个 Glyph 对象的集合,其中的 Glyph 对象表示标准控件的选择边框和抓取手柄。Gets a collection of Glyph objects representing the selection borders and grab handles for a standard control.

GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetHitTest(Point)

指示是否应由控件处理在指定点处的鼠标单击。Indicates whether a mouse click at the specified point should be handled by the control.

GetService(Type)

尝试从设计器组件的设计模式站点检索指定类型的服务。Attempts to retrieve the specified type of service from the design mode site of the designer's component.

(继承自 ComponentDesigner)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
HookChildControls(Control)

将来自指定控件的子控件的消息路由到设计器。Routes messages from the child controls of the specified control to the designer.

Initialize(IComponent)

使用指定的组件初始化设计器。Initializes the designer with the specified component.

InitializeExistingComponent(IDictionary)

重新初始化现有组件。Re-initializes an existing component.

InitializeNewComponent(IDictionary)

初始化新创建的组件。Initializes a newly created component.

InitializeNonDefault()

将控件的属性初始化为任何非默认值。Initializes properties of the control to any non-default values.

InternalControlDesigner(Int32)

返回 ControlDesigner 中具有指定索引的内部控件设计器。Returns the internal control designer with the specified index in the ControlDesigner.

InvokeGetInheritanceAttribute(ComponentDesigner)

获取指定 InheritanceAttributeComponentDesignerGets the InheritanceAttribute of the specified ComponentDesigner.

(继承自 ComponentDesigner)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
NumberOfInternalControlDesigners()

返回 ControlDesigner 中内部控件设计器的数目。Returns the number of internal control designers in the ControlDesigner.

OnContextMenu(Int32, Int32)

显示上下文菜单,并提供在上下文菜单将要显示时执行附加处理的机会。Shows the context menu and provides an opportunity to perform additional processing when the context menu is about to be displayed.

OnCreateHandle()

提供在创建控件处理程序之后立即执行附加处理的机会。Provides an opportunity to perform additional processing immediately after the control handle has been created.

OnDragComplete(DragEventArgs)

接收调用以清理拖放操作。Receives a call to clean up a drag-and-drop operation.

OnDragDrop(DragEventArgs)

在将拖放对象放置到控件设计器视图上时接收调用。Receives a call when a drag-and-drop object is dropped onto the control designer view.

OnDragEnter(DragEventArgs)

在拖放操作进入控件设计器视图时接收调用。Receives a call when a drag-and-drop operation enters the control designer view.

OnDragLeave(EventArgs)

在拖放操作离开控件设计器视图时接收调用。Receives a call when a drag-and-drop operation leaves the control designer view.

OnDragOver(DragEventArgs)

在控件设计器视图上拖动拖放对象时接收调用。Receives a call when a drag-and-drop object is dragged over the control designer view.

OnGiveFeedback(GiveFeedbackEventArgs)

在进行拖放操作时接收调用,以在拖动操作进行的同时基于鼠标的位置提供可视提示。Receives a call when a drag-and-drop operation is in progress to provide visual cues based on the location of the mouse while a drag operation is in progress.

OnMouseDragBegin(Int32, Int32)

当响应在组件上按住鼠标左键不放这一操作时接收调用。Receives a call in response to the left mouse button being pressed and held while over the component.

OnMouseDragEnd(Boolean)

在拖放操作结束时接收调用,以完成或取消此次操作。Receives a call at the end of a drag-and-drop operation to complete or cancel the operation.

OnMouseDragMove(Int32, Int32)

为拖放操作期间的每一次鼠标移动接收调用。Receives a call for each movement of the mouse during a drag-and-drop operation.

OnMouseEnter()

当鼠标首次进入控件时接收调用。Receives a call when the mouse first enters the control.

OnMouseHover()

鼠标在控件上悬停后接收调用。Receives a call after the mouse hovers over the control.

OnMouseLeave()

当鼠标首次进入控件时接收调用。Receives a call when the mouse first enters the control.

OnPaintAdornments(PaintEventArgs)

当设计器正在管理的控件绘制了它的图面时接收调用,这样设计器就可以在控件顶部绘制任意附加装饰。Receives a call when the control that the designer is managing has painted its surface so the designer can paint any additional adornments on top of the control.

OnSetComponentDefaults()

在设计器初始化时调用。Called when the designer is initialized.

OnSetCursor()

在每次需要设置光标时接收调用。Receives a call each time the cursor needs to be set.

PostFilterAttributes(IDictionary)

允许设计器从通过 TypeDescriptor 公开的特性集中更改或移除项。Allows a designer to change or remove items from the set of attributes that it exposes through a TypeDescriptor.

(继承自 ComponentDesigner)
PostFilterEvents(IDictionary)

允许设计器从通过 TypeDescriptor 公开的事件集中更改或移除项。Allows a designer to change or remove items from the set of events that it exposes through a TypeDescriptor.

(继承自 ComponentDesigner)
PostFilterProperties(IDictionary)

允许设计器从通过 TypeDescriptor 公开的属性集中更改或移除项。Allows a designer to change or remove items from the set of properties that it exposes through a TypeDescriptor.

(继承自 ComponentDesigner)
PreFilterAttributes(IDictionary)

允许设计器在通过 TypeDescriptor 公开的特性集中添加项。Allows a designer to add to the set of attributes that it exposes through a TypeDescriptor.

(继承自 ComponentDesigner)
PreFilterEvents(IDictionary)

允许设计器在通过 TypeDescriptor 公开的事件集中添加项。Allows a designer to add to the set of events that it exposes through a TypeDescriptor.

(继承自 ComponentDesigner)
PreFilterProperties(IDictionary)

调整组件通过 TypeDescriptor 公开的属性集。Adjusts the set of properties the component exposes through a TypeDescriptor.

RaiseComponentChanged(MemberDescriptor, Object, Object)

通知 IComponentChangeService 此组件已被更改。Notifies the IComponentChangeService that this component has been changed.

(继承自 ComponentDesigner)
RaiseComponentChanging(MemberDescriptor)

通知 IComponentChangeService 此组件即将被更改。Notifies the IComponentChangeService that this component is about to be changed.

(继承自 ComponentDesigner)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)
UnhookChildControls(Control)

将所指定控件的子级的消息路由到每个控件而不是路由到父级设计器。Routes messages for the children of the specified control to each control rather than to a parent designer.

WndProc(Message)

处理 Windows 消息,并可以选择将其路由到控件。Processes Windows messages and optionally routes them to the control.

显式接口实现

IDesignerFilter.PostFilterAttributes(IDictionary)

有关此成员的说明,请参见 PostFilterAttributes(IDictionary) 方法。For a description of this member, see the PostFilterAttributes(IDictionary) method.

(继承自 ComponentDesigner)
IDesignerFilter.PostFilterEvents(IDictionary)

有关此成员的说明,请参见 PostFilterEvents(IDictionary) 方法。For a description of this member, see the PostFilterEvents(IDictionary) method.

(继承自 ComponentDesigner)
IDesignerFilter.PostFilterProperties(IDictionary)

有关此成员的说明,请参见 PostFilterProperties(IDictionary) 方法。For a description of this member, see the PostFilterProperties(IDictionary) method.

(继承自 ComponentDesigner)
IDesignerFilter.PreFilterAttributes(IDictionary)

有关此成员的说明,请参见 PreFilterAttributes(IDictionary) 方法。For a description of this member, see the PreFilterAttributes(IDictionary) method.

(继承自 ComponentDesigner)
IDesignerFilter.PreFilterEvents(IDictionary)

有关此成员的说明,请参见 PreFilterEvents(IDictionary) 方法。For a description of this member, see the PreFilterEvents(IDictionary) method.

(继承自 ComponentDesigner)
IDesignerFilter.PreFilterProperties(IDictionary)

有关此成员的说明,请参见 PreFilterProperties(IDictionary) 方法。For a description of this member, see the PreFilterProperties(IDictionary) method.

(继承自 ComponentDesigner)
ITreeDesigner.Children

有关此成员的说明,请参见 Children 属性。For a description of this member, see the Children property.

(继承自 ComponentDesigner)
ITreeDesigner.Parent

有关此成员的说明,请参见 Parent 属性。For a description of this member, see the Parent property.

(继承自 ComponentDesigner)

适用于

另请参阅