DesignerVerb 类

定义

表示可从设计器中调用的谓词。

C#
public class DesignerVerb : System.ComponentModel.Design.MenuCommand
C#
[System.Runtime.InteropServices.ComVisible(true)]
public class DesignerVerb : System.ComponentModel.Design.MenuCommand
继承
DesignerVerb
派生
属性

示例

下面的代码示例演示如何创建 DesignerVerb 对象并将其添加到组件的设计时快捷菜单。

C#
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.");
        }
    }
}

注解

设计器谓词是与事件处理程序链接的菜单命令。 设计器谓词会在设计时添加到组件的快捷菜单中。 在 Visual Studio 中,每个设计器谓词也会在属性窗口的“说明”窗格中使用 LinkLabel列出。

构造函数

属性

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)

适用于

产品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

另请参阅