通过


ControlDesigner 类

定义

扩展 . 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 一部分在设计时为控件添加属性。 以下示例代码包含与设计器关联的设计器和示例用户控件。 若要生成此示例,请将示例编译为类库,向Windows 窗体项目添加对库的引用,将控件添加到工具箱,并将控件的实例添加到窗体。 指向控件时,将突出显示控件外围的内部轮廓,用于绘制轮廓的颜色对应于 OutlineColor 设计器已添加到控件列出的属性的属性。

添加对 System.Design 程序集的引用以编译代码示例。

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. 
    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的组件的设计器提供基类。 除了从 ComponentDesigner 类继承的方法和功能之外, ControlDesigner 还提供其他方法来支持在设计时扩展和更改关联的 Control 行为。

可以使用 将设计器与类型 相关联。

构造函数

名称 说明
ControlDesigner()

初始化 ControlDesigner 类的新实例。

字段

名称 说明
accessibilityObj

指定设计器的辅助功能对象。

InvalidPoint

定义一个本地 Point 值,表示无效 Point的值。

属性

名称 说明
AccessibilityObject

AccessibleObject获取分配给控件的控件。

ActionLists

获取与设计器关联的组件支持的设计时操作列表。

(继承自 ComponentDesigner)
AssociatedComponents

获取与设计器管理的组件关联的组件的集合。

AutoResizeHandles

获取或设置一个值,该值指示重设大小句柄分配是否取决于属性的值 AutoSize

BehaviorService

BehaviorService从设计环境获取。

Component

获取此设计器正在设计的组件。

(继承自 ComponentDesigner)
Control

获取设计器正在设计的控件。

EnableDragRect

获取一个值,该值指示是否可以在此设计器组件上绘制拖动矩形。

InheritanceAttribute

InheritanceAttribute获取设计器。

InheritanceAttribute

获取一个属性,该特性指示关联组件的继承类型。

(继承自 ComponentDesigner)
Inherited

获取一个值,该值指示是否继承此组件。

(继承自 ComponentDesigner)
ParentComponent

获取 . 的 ControlDesigner父组件。

ParticipatesWithSnapLines

获取一个值, ControlDesigner 该值指示拖动操作期间是否允许对齐线对齐。

SelectionRules

获取指示组件移动功能的选择规则。

SetTextualDefaultProperty

扩展 . Control. 的设计模式行为。

(继承自 ComponentDesigner)
ShadowProperties

获取替代用户设置的属性值的集合。

(继承自 ComponentDesigner)
SnapLines

获取表示此控件的重要对齐点的对象列表 SnapLine

Verbs

获取与设计器关联的组件支持的设计时谓词。

(继承自 ComponentDesigner)

方法

名称 说明
BaseWndProc(Message)

处理Windows消息。

CanBeParentedTo(IDesigner)

指示此设计器的控件是否可以由指定设计器的控件进行父级。

DefWndProc(Message)

为Windows消息提供默认处理。

DisplayError(Exception)

向用户显示有关指定异常的信息。

Dispose()

释放该 ComponentDesigner命令使用的所有资源。

(继承自 ComponentDesigner)
Dispose(Boolean)

释放由托管资源使用 ControlDesigner 的非托管资源,并选择性地释放托管资源。

DoDefaultAction()

在组件的源代码文件中为默认事件创建方法签名,并将用户的光标导航到该位置。

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

为子控件启用设计时功能。

EnableDragDrop(Boolean)

启用或禁用对所设计的控件的拖放支持。

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetControlGlyph(GlyphSelectionType)

返回一个 ControlBodyGlyph 表示此控件的边界。

GetGlyphs(GlyphSelectionType)

获取表示标准控件的选择边框和抓取手柄的对象集合 Glyph

GetHashCode()

用作默认哈希函数。

(继承自 Object)
GetHitTest(Point)

指示控件是否应处理指定点处的鼠标单击。

GetService(Type)

尝试从设计器组件的设计模式站点检索指定的服务类型。

(继承自 ComponentDesigner)
GetType()

获取当前实例的 Type

(继承自 Object)
HookChildControls(Control)

将消息从指定控件的子控件路由到设计器。

Initialize(IComponent)

使用指定的组件初始化设计器。

InitializeExistingComponent(IDictionary)

重新初始化现有组件。

InitializeNewComponent(IDictionary)

初始化新创建的组件。

InitializeNonDefault()

将控件的属性初始化为任何非默认值。

InitializeNonDefault()
已过时.
已过时.

初始化已初始化为默认设置以外的设置的导入组件的设置。

(继承自 ComponentDesigner)
InternalControlDesigner(Int32)

返回具有指定索引的内部 ControlDesigner控件设计器。

InvokeGetInheritanceAttribute(ComponentDesigner)

InheritanceAttribute获取指定的 ComponentDesigner

(继承自 ComponentDesigner)
MemberwiseClone()

创建当前 Object的浅表副本。

(继承自 Object)
NumberOfInternalControlDesigners()

返回内部控件设计器的数目 ControlDesigner

OnContextMenu(Int32, Int32)

显示上下文菜单,并提供在上下文菜单即将显示时执行其他处理的机会。

OnCreateHandle()

提供在创建控制句柄后立即执行其他处理的机会。

OnDragComplete(DragEventArgs)

接收用于清理拖放操作的调用。

OnDragDrop(DragEventArgs)

当拖放对象放置到控件设计器视图中时接收调用。

OnDragEnter(DragEventArgs)

当拖放操作进入控件设计器视图时接收调用。

OnDragLeave(EventArgs)

当拖放操作离开控件设计器视图时接收调用。

OnDragOver(DragEventArgs)

当拖放对象拖动到控件设计器视图上时,接收调用。

OnGiveFeedback(GiveFeedbackEventArgs)

当拖放操作正在进行时接收调用,以便根据鼠标的位置在拖动操作正在进行时提供视觉提示。

OnMouseDragBegin(Int32, Int32)

接收一个调用,以响应在组件上被按下和按住的鼠标左键。

OnMouseDragEnd(Boolean)

在拖放操作结束时接收调用以完成或取消操作。

OnMouseDragMove(Int32, Int32)

在拖放操作期间接收鼠标每次移动的调用。

OnMouseEnter()

当鼠标首次进入控件时接收呼叫。

OnMouseHover()

在鼠标悬停在控件上后接收调用。

OnMouseLeave()

当鼠标首次进入控件时接收呼叫。

OnPaintAdornments(PaintEventArgs)

当设计器所管理的控件绘制其图面时,接收调用,以便设计器可以在控件顶部绘制任何其他装饰。

OnSetComponentDefaults()
已过时.
已过时.

初始化设计器时调用。

OnSetCursor()

每次需要设置游标时接收调用。

PostFilterAttributes(IDictionary)

允许设计器从它通过 a TypeDescriptor. 公开的属性集中更改或删除项。

(继承自 ComponentDesigner)
PostFilterEvents(IDictionary)

允许设计器从它通过 a TypeDescriptor. 公开的事件集中更改或删除项。

(继承自 ComponentDesigner)
PostFilterProperties(IDictionary)

允许设计器从它通过 a TypeDescriptor. 公开的属性集中更改或删除项。

(继承自 ComponentDesigner)
PreFilterAttributes(IDictionary)

允许设计器添加到它通过 a TypeDescriptor. 公开的属性集。

(继承自 ComponentDesigner)
PreFilterEvents(IDictionary)

允许设计器添加到它通过 a TypeDescriptor. 公开的事件集。

(继承自 ComponentDesigner)
PreFilterProperties(IDictionary)

调整组件通过 . TypeDescriptor. 公开的属性集。

RaiseComponentChanged(MemberDescriptor, Object, Object)

通知 IComponentChangeService 此组件已更改。

(继承自 ComponentDesigner)
RaiseComponentChanging(MemberDescriptor)

通知 IComponentChangeService 此组件即将更改。

(继承自 ComponentDesigner)
ToString()

返回一个表示当前对象的字符串。

(继承自 Object)
UnhookChildControls(Control)

将指定控件的子级的消息路由到每个控件而不是父设计器。

WndProc(Message)

处理Windows消息,并选择性地将其路由到控件。

显式接口实现

名称 说明
IDesignerFilter.PostFilterAttributes(IDictionary)

有关此成员的说明,请参阅 PostFilterAttributes(IDictionary) 方法。

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

有关此成员的说明,请参阅 PostFilterEvents(IDictionary) 方法。

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

有关此成员的说明,请参阅 PostFilterProperties(IDictionary) 方法。

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

有关此成员的说明,请参阅 PreFilterAttributes(IDictionary) 方法。

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

有关此成员的说明,请参阅 PreFilterEvents(IDictionary) 方法。

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

有关此成员的说明,请参阅 PreFilterProperties(IDictionary) 方法。

(继承自 ComponentDesigner)
ITreeDesigner.Children

有关此成员的说明,请参阅 Children 该属性。

(继承自 ComponentDesigner)
ITreeDesigner.Parent

有关此成员的说明,请参阅 Parent 该属性。

(继承自 ComponentDesigner)

适用于

另请参阅