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 Forms專案、將控制項新增至 [工具箱],然後將控制項的實例新增至表單。 當您指向控制項時,控制項周邊的內部外框會反白顯示,而用來繪製外框的色彩會對應 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 的行為。

您可以使用 建立設計工具與型別 DesignerAttribute 的關聯。 如需自訂設計階段行為的概觀,請參閱 擴充Design-Time支援

建構函式

ControlDesigner()

初始化 ControlDesigner 類別的新執行個體。

欄位

accessibilityObj

指定設計工具的可及性物件。

InvalidPoint

定義表示無效 Point 之值的區域 Point

屬性

AccessibilityObject

取得指定給控制項的 AccessibleObject

ActionLists

取得與設計工具相關之元件所支援的設計階段動作清單。

(繼承來源 ComponentDesigner)
AssociatedComponents

取得元件集合,該集合與設計工具管理的元件相關聯。

AutoResizeHandles

取得或設定值,指出縮放控點的配置是否取決於 AutoSize 屬性的值。

BehaviorService

從設計環境取得 BehaviorService

Component

取得這個設計工具正在設計的元件。

(繼承來源 ComponentDesigner)
Control

取得設計工具正在設計的控制項。

EnableDragRect

取得值,指出是否能將拖曳矩形拖曳至這個設計工具元件上。

InheritanceAttribute

取得設計工具的 InheritanceAttribute

InheritanceAttribute

取得屬性 (Attribute),表示相關元件的繼承 (Inheritance) 型別。

(繼承來源 ComponentDesigner)
Inherited

取得值,表示是否要繼承這個元件。

(繼承來源 ComponentDesigner)
ParentComponent

取得 ControlDesigner 的父元件。

ParentComponent

取得這個設計工具的父元件。

(繼承來源 ComponentDesigner)
ParticipatesWithSnapLines

取得值,指出 ControlDesigner 是否可以在拖曳作業期間採用以對齊線為準的對齊方式。

SelectionRules

取得選取規則,指出元件的移動能力。

SetTextualDefaultProperty

擴充 Control 的設計模式行為。

(繼承來源 ComponentDesigner)
ShadowProperties

取得覆寫使用者設定的屬性值集合。

(繼承來源 ComponentDesigner)
SnapLines

取得 SnapLine 物件的清單,表示此控制項的重要對齊點。

Verbs

取得與設計工具相關元件所支援的設計階段動詞命令 (Verb)。

(繼承來源 ComponentDesigner)

方法

BaseWndProc(Message)

處理 Windows 訊息。

CanBeParentedTo(IDesigner)

指示指定的設計工具控制項是否可以成為這個設計工具控制項的父系。

DefWndProc(Message)

提供 Windows 訊息的預設處理。

DisplayError(Exception)

向使用者顯示指定之例外狀況的相關資訊。

Dispose()

釋放 ComponentDesigner 所使用的所有資源。

(繼承來源 ComponentDesigner)
Dispose(Boolean)

釋放 ControlDesigner 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。

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)

重新初始化現有的元件。

InitializeExistingComponent(IDictionary)

重新初始化現有的元件。

(繼承來源 ComponentDesigner)
InitializeNewComponent(IDictionary)

初始化新建立的元件。

InitializeNewComponent(IDictionary)

初始化新建立的元件。

(繼承來源 ComponentDesigner)
InitializeNonDefault()

將控制項的屬性初始化為任何非預設值。

InitializeNonDefault()
已淘汰.
已淘汰.

初始化已初始化為預設值以外設定的匯入元件設定。

(繼承來源 ComponentDesigner)
InternalControlDesigner(Int32)

傳回 ControlDesigner 中含指定索引的內部控制項設計工具。

InvokeGetInheritanceAttribute(ComponentDesigner)

取得指定 InheritanceAttributeComponentDesigner

(繼承來源 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)

允許設計工具變更或移除它經由 TypeDescriptor 公開的屬性集中的項目。

(繼承來源 ComponentDesigner)
PostFilterEvents(IDictionary)

允許設計工具變更或移除它經由 TypeDescriptor 公開的事件集中的項目。

(繼承來源 ComponentDesigner)
PostFilterProperties(IDictionary)

允許設計工具變更或移除它經由 TypeDescriptor 公開的屬性集中的項目。

(繼承來源 ComponentDesigner)
PreFilterAttributes(IDictionary)

允許設計工具加入至它經由 TypeDescriptor 公開的屬性集。

(繼承來源 ComponentDesigner)
PreFilterEvents(IDictionary)

允許設計工具加入至它經由 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)

適用於

另請參閱