DesignerVerb Classe

Définition

Représente un verbe qui peut être appelé à partir d'un concepteur.

public ref class DesignerVerb : System::ComponentModel::Design::MenuCommand
public class DesignerVerb : System.ComponentModel.Design.MenuCommand
[System.Runtime.InteropServices.ComVisible(true)]
public class DesignerVerb : System.ComponentModel.Design.MenuCommand
type DesignerVerb = class
    inherit MenuCommand
[<System.Runtime.InteropServices.ComVisible(true)>]
type DesignerVerb = class
    inherit MenuCommand
Public Class DesignerVerb
Inherits MenuCommand
Héritage
DesignerVerb
Dérivé
Attributs

Exemples

L’exemple de code suivant montre comment créer DesignerVerb des objets et les ajouter au menu contextuel au moment du design pour un composant.

#using <system.dll>
#using <system.design.dll>
#using <system.windows.forms.dll>

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

/* This sample demonstrates a designer that adds menu commands
to the design-time shortcut menu for a component.

To test this sample, build the code for the component as a class library,
add the resulting component to the toolbox, open a form in design mode,
and drag the component from the toolbox onto the form.

The component should appear in the component tray beneath the form.
Right-click the component.  The verbs should appear in the shortcut menu.
*/
// This is a designer class which provides designer verb menu commands for
// the associated component. This code is called by the design environment at design-time.
private ref class MyDesigner: public ComponentDesigner
{
public:

   property DesignerVerbCollection^ Verbs 
   {
      // DesignerVerbCollection is overridden from ComponentDesigner
      virtual DesignerVerbCollection^ get() override
      {
         if ( m_Verbs == nullptr )
         {
            // Create and initialize the collection of verbs
            m_Verbs = gcnew DesignerVerbCollection;
            m_Verbs->Add( gcnew DesignerVerb( "First Designer Verb",gcnew EventHandler( this, &MyDesigner::OnFirstItemSelected ) ) );
            m_Verbs->Add( gcnew DesignerVerb( "Second Designer Verb",gcnew EventHandler( this, &MyDesigner::OnSecondItemSelected ) ) );
         }

         return m_Verbs;
      }
   }
   MyDesigner(){}

private:
   DesignerVerbCollection^ m_Verbs;
   void OnFirstItemSelected( Object^ /*sender*/, EventArgs^ /*args*/ )
   {
      // Display a message
      MessageBox::Show( "The first designer verb was invoked." );
   }

   void OnSecondItemSelected( Object^ /*sender*/, EventArgs^ /*args*/ )
   {
      // Display a message
      MessageBox::Show( "The second designer verb was invoked." );
   }
};

// Associate MyDesigner with this component type using a DesignerAttribute
[Designer(MyDesigner::typeid)]
public ref class Component1: public System::ComponentModel::Component{};
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;

/* This sample demonstrates a designer that adds menu commands
    to the design-time shortcut menu for a component.

    To test this sample, build the code for the component as a class library, 
    add the resulting component to the toolbox, open a form in design mode, 
    and drag the component from the toolbox onto the form. 

    The component should appear in the component tray beneath the form. 
    Right-click the component.  The verbs should appear in the shortcut menu.
*/

namespace CSDesignerVerb
{
    // Associate MyDesigner with this component type using a DesignerAttribute
    [Designer(typeof(MyDesigner))]
    public class Component1 : System.ComponentModel.Component
    {
    }

    // This is a designer class which provides designer verb menu commands for 
    // the associated component. This code is called by the design environment at design-time.
    internal class MyDesigner : ComponentDesigner
    {
        DesignerVerbCollection m_Verbs;

        // DesignerVerbCollection is overridden from ComponentDesigner
        public override DesignerVerbCollection Verbs
        {
            get 
            {
                if (m_Verbs == null) 
                {
                    // Create and initialize the collection of verbs
                    m_Verbs = new DesignerVerbCollection();
            
                    m_Verbs.Add( new DesignerVerb("First Designer Verb", new EventHandler(OnFirstItemSelected)) );
                    m_Verbs.Add( new DesignerVerb("Second Designer Verb", new EventHandler(OnSecondItemSelected)) );
                }
                return m_Verbs;
            }
        }

        MyDesigner() 
        {
        }

        private void OnFirstItemSelected(object sender, EventArgs args) 
        {
            // Display a message
            System.Windows.Forms.MessageBox.Show("The first designer verb was invoked.");
        }

        private void OnSecondItemSelected(object sender, EventArgs args) 
        {
            // Display a message
            System.Windows.Forms.MessageBox.Show("The second designer verb was invoked.");
        }
    }
}
Imports System.ComponentModel
Imports System.Collections
Imports System.ComponentModel.Design

'  This sample demonstrates a designer that adds menu commands
'   to the design-time shortcut menu for a component.
'
'   To test this sample, build the code for the component as a class library, 
'   add the resulting component to the toolbox, open a form in design mode, 
'   and drag the component from the toolbox onto the form. 
'
'   The component should appear in the component tray beneath the form. 
'   Right-click the component.  The verbs should appear in the shortcut menu.

Namespace VBDesignerVerb
    ' Associate MyDesigner with this component type using a DesignerAttribute
    <Designer(GetType(MyDesigner))> _
    Public Class Component1
        Inherits System.ComponentModel.Component
    End Class 


    '  This is a designer class which provides designer verb menu commands for 
    '  the associated component. This code is called by the design environment at design-time.    
    Friend Class MyDesigner
        Inherits ComponentDesigner

        Private m_Verbs As DesignerVerbCollection

        ' DesignerVerbCollection is overridden from ComponentDesigner
        Public Overrides ReadOnly Property Verbs() As DesignerVerbCollection
            Get
                If m_Verbs Is Nothing Then
                    ' Create and initialize the collection of verbs
                    m_Verbs = New DesignerVerbCollection()
                    m_Verbs.Add( New DesignerVerb("First Designer Verb", New EventHandler(AddressOf OnFirstItemSelected)) )
                    m_Verbs.Add( New DesignerVerb("Second Designer Verb", New EventHandler(AddressOf OnSecondItemSelected)) )
                End If
                Return m_Verbs
            End Get
        End Property

        Sub New()
        End Sub 

        Private Sub OnFirstItemSelected(ByVal sender As Object, ByVal args As EventArgs)
            ' Display a message
            System.Windows.Forms.MessageBox.Show("The first designer verb was invoked.")
        End Sub 

        Private Sub OnSecondItemSelected(ByVal sender As Object, ByVal args As EventArgs)
            ' Display a message
            System.Windows.Forms.MessageBox.Show("The second designer verb was invoked.")
        End Sub 
    End Class 
End Namespace

Remarques

Un verbe de concepteur est une commande de menu liée à un gestionnaire d'événements. Designer verbes sont ajoutés au menu contextuel d’un composant au moment de la conception. Dans Visual Studio, chaque verbe du concepteur est également répertorié, à l’aide d’un LinkLabel, dans le volet Description du Fenêtre Propriétés.

Constructeurs

DesignerVerb(String, EventHandler)

Initialise une nouvelle instance de la classe DesignerVerb.

DesignerVerb(String, EventHandler, CommandID)

Initialise une nouvelle instance de la classe DesignerVerb.

Propriétés

Checked

Obtient ou définit une valeur indiquant si cet élément de menu est coché.

(Hérité de MenuCommand)
CommandID

Obtient le CommandID associé à cette commande de menu.

(Hérité de MenuCommand)
Description

Obtient ou définit la description de l'élément de menu pour le verbe.

Enabled

Obtient une valeur indiquant si cet élément de menu est disponible.

(Hérité de MenuCommand)
OleStatus

Obtient le code d'état de la commande OLE pour cet élément de menu.

(Hérité de MenuCommand)
Properties

Obtient les propriétés publiques associées au MenuCommand.

(Hérité de MenuCommand)
Supported

Obtient ou définit une valeur indiquant si cet élément de menu est pris en charge.

(Hérité de MenuCommand)
Text

Obtient le texte de description de la commande sous forme de verbe contenue dans le menu.

Visible

Obtient ou définit une valeur indiquant si cet élément de menu est visible.

(Hérité de MenuCommand)

Méthodes

Equals(Object)

Détermine si l'objet spécifié est égal à l'objet actuel.

(Hérité de Object)
GetHashCode()

Fait office de fonction de hachage par défaut.

(Hérité de Object)
GetType()

Obtient le Type de l'instance actuelle.

(Hérité de Object)
Invoke()

Appelle la commande.

(Hérité de MenuCommand)
Invoke(Object)

Appelle la commande avec le paramètre donné.

(Hérité de MenuCommand)
MemberwiseClone()

Crée une copie superficielle du Object actuel.

(Hérité de Object)
OnCommandChanged(EventArgs)

Déclenche l’événement CommandChanged.

(Hérité de MenuCommand)
ToString()

Substitue ToString().

Événements

CommandChanged

Se produit lorsque la commande de menu est modifiée.

(Hérité de MenuCommand)

S’applique à

Voir aussi