IDesigner Interface

Definição

Fornece a estrutura básica para construir um designer personalizado.

public interface class IDesigner : IDisposable
[System.Runtime.InteropServices.ComVisible(true)]
public interface IDesigner : IDisposable
public interface IDesigner : IDisposable
[<System.Runtime.InteropServices.ComVisible(true)>]
type IDesigner = interface
    interface IDisposable
type IDesigner = interface
    interface IDisposable
Public Interface IDesigner
Implements IDisposable
Derivado
Atributos
Implementações

Exemplos

Este exemplo demonstra uma IDesigner implementação que armazena uma referência local ao seu componente, executa uma ação padrão quando o componente é duplo clicado e fornece um comando de menu para verbos designer.

#using <System.Windows.Forms.dll>
#using <System.Data.dll>
#using <System.Drawing.dll>
#using <System.dll>

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

public ref class ExampleIDesigner: public System::ComponentModel::Design::IDesigner
{
private:

   // Local reference to the designer's component.
   IComponent^ component;

public:

   property System::ComponentModel::IComponent^ Component 
   {
      // Public accessor to the designer's component.
      virtual System::ComponentModel::IComponent^ get()
      {
         return component;
      }
   }
   ExampleIDesigner(){}

   virtual void Initialize( System::ComponentModel::IComponent^ component )
   {
      // This method is called after a designer for a component is created,
      // and stores a reference to the designer's component.
      this->component = component;
   }

   // This method peforms the 'default' action for the designer. The default action 
   // for a basic IDesigner implementation is invoked when the designer's component 
   // is double-clicked. By default, a component associated with a basic IDesigner 
   // implementation is displayed in the design-mode component tray.
   virtual void DoDefaultAction()
   {
      // Shows a message box indicating that the default action for the designer was invoked.
      MessageBox::Show( "The DoDefaultAction method of an IDesigner implementation was invoked.", "Information" );
   }

   property System::ComponentModel::Design::DesignerVerbCollection^ Verbs 
   {
      // Returns a collection of designer verb menu items to show in the 
      // shortcut menu for the designer's component.
      [PermissionSetAttribute(SecurityAction::Demand, Name="FullTrust")]
      virtual System::ComponentModel::Design::DesignerVerbCollection^ get()
      {
         DesignerVerbCollection^ verbs = gcnew DesignerVerbCollection;
         DesignerVerb^ dv1 = gcnew DesignerVerb( "Display Component Name",gcnew EventHandler( this, &ExampleIDesigner::ShowComponentName ) );
         verbs->Add( dv1 );
         return verbs;
      }
   }

private:

   // Event handler for displaying a message box showing the designer's component's name.
   void ShowComponentName( Object^ /*sender*/, EventArgs^ /*e*/ )
   {
      if ( this->Component != nullptr )
            MessageBox::Show( this->Component->Site->Name, "Designer Component's Name" );
   }

public:

   // Provides an opportunity to release resources before object destruction.
   ~ExampleIDesigner(){}

};

// A DesignerAttribute associates the example IDesigner with an example control.

[DesignerAttribute(ExampleIDesigner::typeid)]
public ref class TestControl: public System::Windows::Forms::UserControl
{
public:
   TestControl(){}

};
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace IDesignerExample
{	
    // A DesignerAttribute associates the example IDesigner with an example control.
    [DesignerAttribute(typeof(ExampleIDesigner))]
    public class TestControl : System.Windows.Forms.UserControl
    {				
        public TestControl()
        {	
        }
    }

    public class ExampleIDesigner : System.ComponentModel.Design.IDesigner
    {
        // Local reference to the designer's component.
        private IComponent component; 
        // Public accessor to the designer's component.
        public System.ComponentModel.IComponent Component
        {
            get
            {
                return component;
            }            
        }

        public ExampleIDesigner()
        {            
        }

        public void Initialize(System.ComponentModel.IComponent component)
        {
            // This method is called after a designer for a component is created,
            // and stores a reference to the designer's component.
            this.component = component;
        }        
        
        // This method peforms the 'default' action for the designer. The default action 
        // for a basic IDesigner implementation is invoked when the designer's component 
        // is double-clicked. By default, a component associated with a basic IDesigner 
        // implementation is displayed in the design-mode component tray.
        public void DoDefaultAction()
        {
            // Shows a message box indicating that the default action for the designer was invoked.
            MessageBox.Show("The DoDefaultAction method of an IDesigner implementation was invoked.", "Information");
        }

        // Returns a collection of designer verb menu items to show in the 
        // shortcut menu for the designer's component.
        public System.ComponentModel.Design.DesignerVerbCollection Verbs
        {
            get
            {
                DesignerVerbCollection verbs = new DesignerVerbCollection();
                DesignerVerb dv1 = new DesignerVerb("Display Component Name", new EventHandler(this.ShowComponentName));
                verbs.Add( dv1 );
                return verbs;
            }
        }

        // Event handler for displaying a message box showing the designer's component's name.
        private void ShowComponentName(object sender, EventArgs e)
        {
            if( this.Component != null )
                MessageBox.Show( this.Component.Site.Name, "Designer Component's Name" );
        }

        // Provides an opportunity to release resources before object destruction.
        public void Dispose()
        {        
        }
    }
}
Imports System.Collections
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Drawing
Imports System.Windows.Forms

' A DesignerAttribute associates the example IDesigner with an example control.
<DesignerAttribute(GetType(ExampleIDesigner))> _
Public Class TestControl
    Inherits System.Windows.Forms.UserControl

    Public Sub New()
    End Sub
End Class

<System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
Public Class ExampleIDesigner
    Implements System.ComponentModel.Design.IDesigner

    ' Local reference to the designer's component.
    Private _component As IComponent

    ' Public accessor to the designer's component.
    Public ReadOnly Property Component() As System.ComponentModel.IComponent Implements IDesigner.Component
        Get
            Return _component
        End Get
    End Property

    Public Sub New()
    End Sub

    Public Sub Initialize(ByVal component As System.ComponentModel.IComponent) Implements IDesigner.Initialize
        ' This method is called after a designer for a component is created,
        ' and stores a reference to the designer's component.
        Me._component = component
    End Sub

    ' This method peforms the 'default' action for the designer. The default action 
    ' for a basic IDesigner implementation is invoked when the designer's component 
    ' is double-clicked. By default, a component associated with a basic IDesigner 
    ' implementation is displayed in the design-mode component tray.
    Public Sub DoDefaultAction() Implements IDesigner.DoDefaultAction
        ' Shows a message box indicating that the default action for the designer was invoked.
        MessageBox.Show("The DoDefaultAction method of an IDesigner implementation was invoked.", "Information")
    End Sub

    ' Returns a collection of designer verb menu items to show in the 
    ' shortcut menu for the designer's component.
    Public ReadOnly Property Verbs() As System.ComponentModel.Design.DesignerVerbCollection Implements IDesigner.Verbs
        Get
            Dim verbs_ As New DesignerVerbCollection()
            Dim dv1 As New DesignerVerb("Display Component Name", New EventHandler(AddressOf Me.ShowComponentName))
            verbs_.Add(dv1)
            Return verbs_
        End Get
    End Property

    ' Event handler for displaying a message box showing the designer's component's name.
    Private Sub ShowComponentName(ByVal sender As Object, ByVal e As EventArgs)
        If (Me.Component IsNot Nothing) Then
            MessageBox.Show(Me.Component.Site.Name, "Designer Component's Name")
        End If
    End Sub

    ' Provides an opportunity to release resources before object destruction.
    Public Sub Dispose() Implements IDisposable.Dispose
    End Sub

End Class

Observações

A IDesigner interface fornece uma interface através da qual pode implementar serviços básicos para um designer. Um designer pode modificar o comportamento de um componente no momento do design e pode fornecer os seus próprios serviços e comportamento. Um designer está ativo apenas em tempo de design, e deve estar associado a um tipo de componente usando a DesignerAttribute para ser carregado quando um componente do tipo associado é criado em tempo de projeto.

A IDesigner interface fornece métodos e propriedades que pode implementar para fornecer um comportamento personalizado no momento do design.

Implemente o Initialize método de um designer para realizar ações quando um componente é criado. Isto pode ser útil se um componente tiver uma configuração especial no momento do projeto, ou se a sua configuração mudar dependendo das condições que o projetista conseguir determinar.

Um designer pode fornecer comandos de menu no menu de atalho que é exibido quando o utilizador clica com o botão direito num componente ou controlo no ambiente de design-time. Pode implementar a Verbs propriedade para definir um acesso get que devolve um DesignerVerbCollection contendo os DesignerVerb objetos para gerar comandos de menu.

Um designer de um componente que aparece na bandeja de componentes pode realizar uma ação padrão quando o componente é duplo clique. Implemente o DoDefaultAction método para especificar o comportamento a realizar quando o componente é clicado duas vezes.

Um projetista pode também utilizar os serviços disponíveis em tempo de conceção para realizar uma variedade de tarefas, incluindo o levantamento do ambiente atual em tempo de projeto para componentes e as suas propriedades, leitura e definição dos valores das propriedades dos componentes, gestão da caixa de ferramentas, gestão de componentes selecionados ou apresentação de uma interface de utilizador que possa ser usada para configurar valores ou aplicar processamento adicional.

Para implementar um designer para um controlo que pode ser colocado num formulário, pode herdar da ControlDesigner classe. Controlos cujo designer associado não deriva são ControlDesigner exibidos na bandeja de componentes. As ComponentDesigner classes and ControlDesigner implementam a IDesigner interface e fornecem suporte adicional em tempo de design que pode ser útil para autores de designers. Para mais informações, consulte a documentação de referência destas disciplinas.

Para uma visão geral da criação de componentes de design, consulte Extensão Design-Time Suporte.

Propriedades

Name Description
Component

Obtém o componente base que este designer está a desenhar.

Verbs

Obtém uma coleção dos verbos do tempo de design suportados pelo designer.

Métodos

Name Description
Dispose()

Realiza tarefas definidas pela aplicação associadas à libertação, libertação ou reinício de recursos não geridos.

(Herdado de IDisposable)
DoDefaultAction()

Executa a ação padrão para este designer.

Initialize(IComponent)

Inicializa o designer com o componente especificado.

Aplica-se a

Ver também