共用方式為


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 assembly 的參考,以便編譯程式碼範例。

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

建構函式

名稱 Description
ControlDesigner()

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

欄位

名稱 Description
accessibilityObj

指定設計者的無障礙物件。

InvalidPoint

定義一個 Point 局部值,代表一個無效 Point值的值。

屬性

名稱 Description
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)

方法

名稱 Description
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)

返回 a 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)

允許設計者更改或移除其透過 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 訊息,並可選擇性地將其路由至控制項。

明確介面實作

名稱 Description
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)

適用於

另請參閱