DesignerVerb Класс

Определение

Предоставляет команду, которая может быть вызвана из конструктора.Represents a verb that can be invoked from a designer.

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
Public Class DesignerVerb
Inherits MenuCommand
Наследование
DesignerVerb
Производный
Атрибуты

Примеры

В следующем примере кода показано, как создать объекты DesignerVerb и добавить их в контекстное меню времени разработки для компонента.The following code example demonstrates how to create DesignerVerb objects and add them to the design-time shortcut menu for a component.

#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

Комментарии

Команда конструктора ― это команда меню, связанная с обработчиком событий.A designer verb is a menu command linked to an event handler. Команды конструктора добавляются в контекстное меню компонента во время разработки.Designer verbs are added to a component's shortcut menu at design time. В Visual Studio каждая команда конструктора также перечисляется с помощью LinkLabelна панели описание окно свойств.In Visual Studio, each designer verb is also listed, using a LinkLabel, in the Description pane of the Properties window.

Конструкторы

DesignerVerb(String, EventHandler)

Инициализация нового экземпляра класса DesignerVerb.Initializes a new instance of the DesignerVerb class.

DesignerVerb(String, EventHandler, CommandID)

Инициализация нового экземпляра класса DesignerVerb.Initializes a new instance of the DesignerVerb class.

Свойства

Checked

Получает или задает значение, указывающее, отмечена ли данная команда меню.Gets or sets a value indicating whether this menu item is checked.

(Унаследовано от MenuCommand)
CommandID

Получает идентификатор CommandID, связанный с данной командой меню.Gets the CommandID associated with this menu command.

(Унаследовано от MenuCommand)
Description

Получает или задает описание команды меню для команды.Gets or sets the description of the menu item for the verb.

Enabled

Получает значение, показывающее, доступна ли данная команда меню.Gets a value indicating whether this menu item is available.

(Унаследовано от MenuCommand)
OleStatus

Получает код состояния команды OLE для данной команды меню.Gets the OLE command status code for this menu item.

(Унаследовано от MenuCommand)
Properties

Возвращает открытые свойства, сопоставленные объекту MenuCommand.Gets the public properties associated with the MenuCommand.

(Унаследовано от MenuCommand)
Supported

Получает или задает значение, показывающее, поддерживается ли данная команда меню.Gets or sets a value indicating whether this menu item is supported.

(Унаследовано от MenuCommand)
Text

Возвращает текстовое описание команды меню.Gets the text description for the verb command on the menu.

Visible

Возвращает или задает значение, указывающее, отображается ли данная команда меню.Gets or sets a value indicating whether this menu item is visible.

(Унаследовано от MenuCommand)

Методы

Equals(Object)

Определяет, равен ли указанный объект текущему объекту.Determines whether the specified object is equal to the current object.

(Унаследовано от Object)
GetHashCode()

Служит в качестве хэш-функции по умолчанию.Serves as the default hash function.

(Унаследовано от Object)
GetType()

Возвращает объект Type для текущего экземпляра.Gets the Type of the current instance.

(Унаследовано от Object)
Invoke()

Вызывает команду.Invokes the command.

(Унаследовано от MenuCommand)
Invoke(Object)

Вызывает команду с заданным параметром.Invokes the command with the given parameter.

(Унаследовано от MenuCommand)
MemberwiseClone()

Создает неполную копию текущего объекта Object.Creates a shallow copy of the current Object.

(Унаследовано от Object)
OnCommandChanged(EventArgs)

Порождает событие CommandChanged.Raises the CommandChanged event.

(Унаследовано от MenuCommand)
ToString()

Переопределяет ToString().Overrides ToString().

События

CommandChanged

Возникает при изменении команды меню.Occurs when the menu command changes.

(Унаследовано от MenuCommand)

Применяется к

Дополнительно