共用方式為


DesignerVerb 類別

定義

表示可從設計工具叫用 (Invoke) 的動詞命令 (Verb)。

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
繼承
DesignerVerb
衍生
屬性

範例

下列程式代碼範例示範如何建立 DesignerVerb 物件,並將其新增至元件的設計時間快捷方式功能表。

#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

備註

設計工具動詞命令是連結至事件處理常式的功能表命令。 Designer 動詞命令會在設計時間新增至元件的快捷方式功能表。 在 Visual Studio 中,也會使用 LinkLabel屬性視窗 的 [描述] 窗格中列出每個設計工具動詞。

建構函式

DesignerVerb(String, EventHandler)

初始化 DesignerVerb 類別的新執行個體。

DesignerVerb(String, EventHandler, CommandID)

初始化 DesignerVerb 類別的新執行個體。

屬性

Checked

取得或設定值,表示是否檢查這個功能表項目。

(繼承來源 MenuCommand)
CommandID

取得與這個功能表命令相關的 CommandID

(繼承來源 MenuCommand)
Description

取得或設定動詞命令的功能表項目描述。

Enabled

取得值,表示是否可以使用這個功能表項目。

(繼承來源 MenuCommand)
OleStatus

取得這個功能表項目的 OLE 命令狀態程式碼。

(繼承來源 MenuCommand)
Properties

取得與 MenuCommand 關聯的公用屬性。

(繼承來源 MenuCommand)
Supported

取得或設定值,表示是否支援這個功能表項目。

(繼承來源 MenuCommand)
Text

取得功能表上動詞命令的文字描述。

Visible

取得或設定值,表示功能表項目是否為可見。

(繼承來源 MenuCommand)

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
Invoke()

叫用命令。

(繼承來源 MenuCommand)
Invoke(Object)

叫用具有指定參數的命令。

(繼承來源 MenuCommand)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
OnCommandChanged(EventArgs)

引發 CommandChanged 事件。

(繼承來源 MenuCommand)
ToString()

覆寫 ToString()

事件

CommandChanged

發生於功能表命令變更時。

(繼承來源 MenuCommand)

適用於

另請參閱