IDesigner Interfaccia

Definizione

Fornisce il framework di base per la compilazione di una finestra di progettazione personalizzata.

public interface class IDesigner : IDisposable
public interface IDesigner : IDisposable
[System.Runtime.InteropServices.ComVisible(true)]
public interface IDesigner : IDisposable
type IDesigner = interface
    interface IDisposable
[<System.Runtime.InteropServices.ComVisible(true)>]
type IDesigner = interface
    interface IDisposable
Public Interface IDesigner
Implements IDisposable
Derivato
Attributi
Implementazioni

Esempio

In questo esempio viene illustrata un'implementazione IDesigner che archivia un riferimento locale al relativo componente, esegue un'azione predefinita quando il componente viene fatto doppio clic e fornisce un comando di menu verbo della finestra di progettazione.

#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

Commenti

L'interfaccia IDesigner fornisce un'interfaccia tramite la quale è possibile implementare servizi di base per una finestra di progettazione. Una finestra di progettazione può modificare il comportamento di un componente in fase di progettazione e può fornire servizi e comportamenti personalizzati. Una finestra di progettazione è attiva solo in fase di progettazione e deve essere associata a un tipo di componente usando un DesignerAttribute oggetto per essere caricato quando viene creato un componente del tipo associato in fase di progettazione.

L'interfaccia IDesigner fornisce metodi e proprietà che è possibile implementare per fornire un comportamento personalizzato in fase di progettazione.

Implementare il Initialize metodo di una finestra di progettazione per eseguire azioni quando viene creato un componente. Ciò può essere utile se un componente deve avere una configurazione speciale in fase di progettazione o se la relativa configurazione deve cambiare a seconda delle condizioni che la finestra di progettazione può determinare.

Una finestra di progettazione può fornire comandi di menu nel menu di scelta rapida visualizzato quando un utente fa clic con il pulsante destro del mouse su un componente o un controllo nell'ambiente in fase di progettazione. È possibile implementare la Verbs proprietà per definire una funzione di accesso get che restituisce un DesignerVerbCollection oggetto contenente gli DesignerVerb oggetti per la generazione di comandi di menu.

Una finestra di progettazione per un componente visualizzato nella barra dei componenti può eseguire un'azione predefinita quando il componente viene fatto doppio clic. Implementare il metodo per specificare il DoDefaultAction comportamento da eseguire quando il componente viene fatto doppio clic.

Una finestra di progettazione può anche usare i servizi di progettazione disponibili per eseguire diverse attività, tra cui il sondaggio dell'ambiente di progettazione corrente per i componenti e le relative proprietà, la lettura e l'impostazione dei valori delle proprietà dei componenti, la gestione della casella degli strumenti, la gestione dei componenti selezionati o la visualizzazione di un'interfaccia utente che può essere usata per configurare i valori o applicare ulteriori elaborazioni.

Per implementare una finestra di progettazione per un controllo che può essere localizzato in un modulo, è possibile ereditare dalla ControlDesigner classe. I controlli la cui finestra di progettazione associata non deriva da ControlDesigner vengono visualizzati nella barra dei componenti. Le ComponentDesigner classi e ControlDesigner implementano l'interfaccia IDesigner e forniscono un supporto aggiuntivo in fase di progettazione che può essere usato agli autori di designer. Per altre informazioni, vedere la documentazione di riferimento per queste classi.

Per una panoramica della creazione di componenti di progettazione, vedere Estensione del supporto Design-Time.

Proprietà

Component

Ottiene il componente di base in fase di progettazione nella finestra di progettazione.

Verbs

Ottiene un insieme di verbi della fase di progettazione supportati dalla finestra di progettazione.

Metodi

Dispose()

Esegue attività definite dall'applicazione, come rilasciare o reimpostare risorse non gestite.

(Ereditato da IDisposable)
DoDefaultAction()

Esegue l'azione predefinita per questa finestra di progettazione.

Initialize(IComponent)

Inizializza la finestra di progettazione con il componente specificato.

Si applica a

Vedi anche