Freigeben über


ComponentDesigner-Klasse

Erweitert das Entwurfsmodusverhalten einer Komponente.

Namespace: System.ComponentModel.Design
Assembly: System.Design (in system.design.dll)

Syntax

'Declaration
Public Class ComponentDesigner
    Implements ITreeDesigner, IDesigner, IDisposable, IDesignerFilter, _
    IComponentInitializer
'Usage
Dim instance As ComponentDesigner
public class ComponentDesigner : ITreeDesigner, IDesigner, IDisposable, 
    IDesignerFilter, IComponentInitializer
public ref class ComponentDesigner : ITreeDesigner, IDesigner, IDisposable, 
    IDesignerFilter, IComponentInitializer
public class ComponentDesigner implements ITreeDesigner, IDesigner, 
    IDisposable, IDesignerFilter, IComponentInitializer
public class ComponentDesigner implements ITreeDesigner, IDesigner, 
    IDisposable, IDesignerFilter, IComponentInitializer

Hinweise

Die ComponentDesigner-Designerbasisklasse stellt einen einfachen Designer bereit, der das Verhalten einer zugeordneten Komponente im Entwurfsmodus erweitern kann.

ComponentDesigner stellt eine leere IDesignerFilter-Schnittstellenimplementierung bereit, deren Methoden überschrieben werden können, um die Attribute, Eigenschaften und Ereignisse der zugeordneten Komponenten zur Entwurfszeit anzupassen.

Mit einem DesignerAttribute können Sie einem Designer einen Typ zuordnen. Eine Übersicht über das Anpassen des Entwurfszeitverhaltens finden Sie unter Erweitern der Entwurfszeitunterstützung.

Beispiel

Das folgende Codebeispiel enthält eine ComponentDesigner-Beispielimplementierung und eine dem Designer zugeordnete Beispielkomponente. Der Designer implementiert eine Überschreibung der Initialize-Methode, die die Initialize-Basismethode aufruft, eine Überschreibung der DoDefaultAction-Methode, die beim Doppelklicken auf die Komponente eine MessageBox anzeigt, und eine Überschreibung des Verbs-Eigenschaftenaccessors, der im Kontextmenü für die Komponente einen benutzerdefinierten DesignerVerb-Menübefehl bereitstellt.

Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Drawing
Imports System.Windows.Forms

Namespace ExampleComponent

    ' Provides an example component designer.
    Public Class ExampleComponentDesigner
        Inherits System.ComponentModel.Design.ComponentDesigner

        Public Sub New()
        End Sub 'New

        ' This method provides an opportunity to perform processing when a designer is initialized.
        ' The component parameter is the component that the designer is associated with.
        Public Overrides Sub Initialize(ByVal component As System.ComponentModel.IComponent)
            ' Always call the base Initialize method in an override of this method.
            MyBase.Initialize(component)
        End Sub 'Initialize

        ' This method is invoked when the associated component is double-clicked.
        Public Overrides Sub DoDefaultAction()
            MessageBox.Show("The event handler for the default action was invoked.")
        End Sub 'DoDefaultAction

        ' This method provides designer verbs.
        Public Overrides ReadOnly Property Verbs() As System.ComponentModel.Design.DesignerVerbCollection
            Get
                Return New DesignerVerbCollection(New DesignerVerb() {New DesignerVerb("Example Designer Verb Command", New EventHandler(AddressOf Me.onVerb))})
            End Get
        End Property

        ' Event handling method for the example designer verb
        Private Sub onVerb(ByVal sender As Object, ByVal e As EventArgs)
            MessageBox.Show("The event handler for the Example Designer Verb Command was invoked.")
        End Sub 'onVerb
    End Class 'ExampleComponentDesigner

    ' Provides an example component associated with the example component designer.
    <DesignerAttribute(GetType(ExampleComponentDesigner), GetType(IDesigner))> _
     Public Class ExampleComponent
        Inherits System.ComponentModel.Component

        Public Sub New()
        End Sub 'New
    End Class 'ExampleComponent

End Namespace 'ExampleComponent
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Windows.Forms;

namespace ExampleComponent
{   
    // Provides an example component designer.
    public class ExampleComponentDesigner : System.ComponentModel.Design.ComponentDesigner
    {
        public ExampleComponentDesigner()
        {
        }

        // This method provides an opportunity to perform processing when a designer is initialized.
        // The component parameter is the component that the designer is associated with.
        public override void Initialize(System.ComponentModel.IComponent component)
        {
            // Always call the base Initialize method in an override of this method.
            base.Initialize(component);
        }

        // This method is invoked when the associated component is double-clicked.
        public override void DoDefaultAction()
        {
            MessageBox.Show("The event handler for the default action was invoked.");
        }

        // This method provides designer verbs.
        public override System.ComponentModel.Design.DesignerVerbCollection Verbs
        {
            get
            {
                return new DesignerVerbCollection( new DesignerVerb[] { new DesignerVerb("Example Designer Verb Command", new EventHandler(this.onVerb)) } );
            }
        }

        // Event handling method for the example designer verb
        private void onVerb(object sender, EventArgs e)
        {
            MessageBox.Show("The event handler for the Example Designer Verb Command was invoked.");
        }
    }

    // Provides an example component associated with the example component designer.
    [DesignerAttribute(typeof(ExampleComponentDesigner), typeof(IDesigner))]
    public class ExampleComponent : System.ComponentModel.Component
    {       
        public ExampleComponent()
        {
        }
    }
}
#using <System.dll>
#using <System.Design.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>

using namespace System;
using namespace System::Collections;
using namespace System::ComponentModel;
using namespace System::ComponentModel::Design;
using namespace System::Drawing;
using namespace System::Windows::Forms;

// Provides an example component designer.
ref class ExampleComponentDesigner: public ComponentDesigner
{
public:
   ExampleComponentDesigner()
   {
   }

   // This method provides an opportunity to perform processing when a designer is initialized.
   // The component parameter is the component that the designer is associated with.
   virtual void Initialize( IComponent^ component ) override
   {
      // Always call the base Initialize method in an of this method.
      ComponentDesigner::Initialize( component );
   }

   // This method is invoked when the associated component is double-clicked.
   virtual void DoDefaultAction() override
   {
      MessageBox::Show( "The event handler for the default action was invoked." );
   }

   // This method provides designer verbs.
   property DesignerVerbCollection^ Verbs 
   {
      virtual DesignerVerbCollection^ get() override
      {
         array<DesignerVerb^>^ newDesignerVerbs = {gcnew DesignerVerb( "Example Designer Verb Command", gcnew EventHandler( this, &ExampleComponentDesigner::onVerb ) )};
         return gcnew DesignerVerbCollection( newDesignerVerbs );
      }
   }

private:
   // Event handling method for the example designer verb
   void onVerb( Object^ sender, EventArgs^ e )
   {
      MessageBox::Show( "The event handler for the Example Designer Verb Command was invoked." );
   }
};

// Provides an example component associated with the example component designer.

[DesignerAttribute(ExampleComponentDesigner::typeid, IDesigner::typeid)]
ref class ExampleComponent: public Component
{
public:
   ExampleComponent(){}
};
package ExampleComponent;

import System.*;
import System.Collections.*;
import System.ComponentModel.*;
import System.ComponentModel.Design.*;
import System.Drawing.*;
import System.Windows.Forms.*;

// Provides an example component designer.
public class ExampleComponentDesigner
    extends System.ComponentModel.Design.ComponentDesigner
{
    public ExampleComponentDesigner()
    {
    } //ExampleComponentDesigner

    // This method provides an opportunity to perform processing when a
    // designer is initialized.The component parameter is the component that 
    // the designer is associated with.
    public void Initialize(System.ComponentModel.IComponent component)
    {
        // Always call the base Initialize method in an override of this method.
        super.Initialize(component);
    } //Initialize

    // This method is invoked when the associated component is double-clicked.
    public void DoDefaultAction()
    {
        MessageBox.Show("The event handler for the default action was invoked.");
    } //DoDefaultAction

    // This method provides designer verbs.
    /** @property 
     */
    public System.ComponentModel.Design.DesignerVerbCollection get_Verbs()
    {
        return new DesignerVerbCollection(new DesignerVerb[]
            { new DesignerVerb("Example Designer Verb Command",
            new EventHandler(this.OnVerb)) });
    } //get_Verbs

    // Event handling method for the example designer verb
    private void OnVerb(Object sender, EventArgs e)
    {
        MessageBox.Show("The event handler for the Example Designer Verb"
            + " Command was invoked.");
    } //OnVerb
} //ExampleComponentDesigner

// Provides an example component associated with the example component designer.
/** @attribute DesignerAttribute(ExampleComponentDesigner.class, IDesigner.class)
 */
public class ExampleComponent extends System.ComponentModel.Component
{
    public ExampleComponent()
    {
    } //ExampleComponent
} //ExampleComponent

Vererbungshierarchie

System.Object
  System.ComponentModel.Design.ComponentDesigner
     Abgeleitete Klassen

Threadsicherheit

Alle öffentlichen statischen (Shared in Visual Basic) Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.

Plattformen

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 unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

ComponentDesigner-Member
System.ComponentModel.Design-Namespace
IDesigner
IDesignerFilter
DesignerAttribute-Klasse

Weitere Ressourcen

Erweitern der Entwurfszeitunterstützung
Gewusst wie: Zugriff auf Entwurfszeitdienste