DesignerVerb 类 
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示可从设计器中调用的谓词。
public ref class DesignerVerb : System::ComponentModel::Design::MenuCommandpublic class DesignerVerb : System.ComponentModel.Design.MenuCommand[System.Runtime.InteropServices.ComVisible(true)]
public class DesignerVerb : System.ComponentModel.Design.MenuCommandtype DesignerVerb = class
    inherit MenuCommand[<System.Runtime.InteropServices.ComVisible(true)>]
type DesignerVerb = class
    inherit MenuCommandPublic Class DesignerVerb
Inherits MenuCommand- 继承
- 派生
- 属性
示例
下面的代码示例演示如何创建 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
注解
设计器谓词是与事件处理程序链接的菜单命令。 设计器谓词会在设计时添加到组件的快捷菜单中。 在 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) |