다음을 통해 공유


ControlDesigner 클래스

Control의 디자인 모드 동작을 확장합니다.

네임스페이스: System.Windows.Forms.Design
어셈블리: System.Design(system.design.dll)

구문

‘선언
Public Class ControlDesigner
    Inherits ComponentDesigner
‘사용 방법
Dim instance As ControlDesigner
public class ControlDesigner : ComponentDesigner
public ref class ControlDesigner : public ComponentDesigner
public class ControlDesigner extends ComponentDesigner
public class ControlDesigner extends ComponentDesigner

설명

ControlDesignerControl에서 파생된 구성 요소의 디자이너에 대한 기본 클래스를 제공합니다. ControlDesignerComponentDesigner 클래스에서 파생된 메서드 및 기능 외에 디자인 타임에 연관된 Control 동작의 확장 및 변경을 지원하는 추가 메서드를 제공합니다.

DesignerAttribute를 사용하여 형식에 디자이너를 연결할 수 있습니다. 디자인 타임 동작을 사용자 지정하는 방법에 대한 개요를 보려면 디자인 타임 지원 확장을 참조하십시오.

예제

다음 예제의 ControlDesigner 구현에서는 MouseEnterMouseLeave 이벤트의 처리, 디자이너 코드에서 컨트롤 그리기 및 IDesignerFilter 인터페이스 부분을 사용하여 디자인 타임에 컨트롤 속성을 추가하는 작업을 보여 줍니다. 다음 예제 코드에는 디자이너 및 해당 디자이너와 연관된 샘플 사용자 정의 컨트롤이 포함되어 있습니다. 이 샘플을 작성하려면 샘플을 클래스 라이브러리로 컴파일하고, 라이브러리에 대한 참조를 Windows Forms 프로젝트에 추가하고, Toolbox에 컨트롤을 추가하고, 컨트롤의 인스턴스를 폼에 추가합니다. 컨트롤을 가리킬 때 컨트롤 타원의 안쪽 윤곽선이 강조 표시되며 윤곽선을 그리는 데 사용된 색은 컨트롤에 대해 나열된 속성에 디자이너가 추가한 OutlineColor 속성과 일치합니다.

Imports System
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 TestControlDesigner
        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.
        Protected Overrides Sub PreFilterProperties(ByVal properties As System.Collections.IDictionary)
            properties.Add("OutlineColor", TypeDescriptor.CreateProperty(GetType(TestControlDesigner), "OutlineColor", GetType(System.Drawing.Color), Nothing))
        End Sub
    End Class

    ' This example control demonstrates the ExampleControlDesigner.
    <DesignerAttribute(GetType(TestControlDesigner))> _
     Public Class TestControl
        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 Not (components Is Nothing) Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub 
    End Class 

End Namespace
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 );
        }
    }
}
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;
         }
      }
   };

상속 계층 구조

System.Object
   System.ComponentModel.Design.ComponentDesigner
    System.Windows.Forms.Design.ControlDesigner
       System.Windows.Forms.Design.ParentControlDesigner

스레드로부터의 안전성

이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

플랫폼

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

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

참고 항목

참조

ControlDesigner 멤버
System.Windows.Forms.Design 네임스페이스
ComponentDesigner
IDesigner
DesignerAttribute

기타 리소스

디자인 타임 지원 확장