DesignerVerb 类
表示可从设计器中调用的谓词。
**命名空间:**System.ComponentModel.Design
**程序集:**System(在 system.dll 中)
语法
声明
<ComVisibleAttribute(True)> _
Public Class DesignerVerb
Inherits MenuCommand
用法
Dim instance As DesignerVerb
[ComVisibleAttribute(true)]
public class DesignerVerb : MenuCommand
[ComVisibleAttribute(true)]
public ref class DesignerVerb : public MenuCommand
/** @attribute ComVisibleAttribute(true) */
public class DesignerVerb extends MenuCommand
ComVisibleAttribute(true)
public class DesignerVerb extends MenuCommand
备注
设计器谓词是链接到事件处理程序的菜单命令。设计器谓词设计时被添加到了组件的快捷菜单。Visual Studio 中还在“属性”窗口的“说明”窗格中使用 LinkLabel 列出了每个设计器谓词。
提示
应用于此类的 HostProtectionAttribute 属性 (Attribute) 具有以下 Resources 属性 (Property) 值:SharedState。HostProtectionAttribute 不影响桌面应用程序(这些应用程序通常通过双击图标、键入命令或在浏览器中输入 URL 来启动)。有关更多信息,请参见 HostProtectionAttribute 类或 SQL Server 编程和宿主保护属性。
示例
下面的代码示例说明如何创建 DesignerVerb 对象并将它们添加到组件的设计时快捷菜单中。
Imports System
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
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.");
}
}
}
#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{};
.NET Framework 安全性
- NamedPermissionSet 用于对系统资源进行完全访问。要求值:LinkDemand、InheritanceDemand。关联状态:FullTrust
继承层次结构
System.Object
System.ComponentModel.Design.MenuCommand
System.ComponentModel.Design.DesignerVerb
System.Web.UI.Design.TemplateEditingVerb
线程安全
此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。
平台
Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
请参见
参考
DesignerVerb 成员
System.ComponentModel.Design 命名空间
MenuCommand
IMenuCommandService