定义命令时,使用属性。该属性需要一个字符串值用作正在定义的命令的全局名称。除了全局命令名称外,该属性还可以接受以下值:CommandMethodCommandMethodCommandMethod
下表列出了可用于定义命令行为的可用标志。
Instance and Static Command Methods
Command methods may be declared as either instance or static methods. Static command methods are declared with the static keyword in C#, or with the keyword in VB .NET. Instance command methods are public class members that are not declared with the static or keyword. SharedShared For an instance command method, the method's enclosing type is instantiated separately for each open document. This means that each document gets a private copy of the command's instance data. Thus there is no danger of overwriting document-specific data when the user switches documents. If an instance method needs to share data globally, it can do so by declaring static or Shared member variables. For a static command method, the managed wrapper runtime module does not need to instantiate the enclosing type. A single copy of the method's data is used, regardless of the document context. Static commands normally do not use per-document data and do not require special consideration for MDI mode. Instance and static methods can be defined with command flags to accommodate special requirements. For example, an instance method may be declared with an attribute that sets the flag. This means that the command runs in the application execution context, but also maintains per-document data. An AutoCAD example of such a command is the PROPERTIES command. CommandFlags.Session Likewise, a static method may be declared without the flag. This combination is useful for commands that run in the document context but do not need to maintain per-document data. CommandFlags.Session Syntax to Define a Command下面演示如何创建定义名为 CheckForPickfirstSelect 的命令的属性。该属性还使用命令标志来指示允许命令使用在启动命令之前选择的对象。CommandMethodUsePickSet VB.NET<CommandMethod("CheckForPickfirstSelection", CommandFlags.UsePickSet)> _ Public Sub CheckForPickfirstSelection() . . . End Sub C#[CommandMethod("CheckForPickfirstSelection", CommandFlags.UsePickSet)] public static void CheckForPickfirstSelection() { . . . } 您可以通过在 VB.NET 中使用 + 运算符来指定使用多个标志,|C# 中的运算符。 VB.NET<CommandMethod("CheckForPickfirstSelection", CommandFlags.UsePickSet + _ CommandFlags.NoBlockEditor)> _ Public Sub CheckForPickfirstSelection() . . . End Sub C#[CommandMethod("CheckForPickfirstSelection", CommandFlags.UsePickSet | CommandFlags.NoBlockEditor)] public static void CheckForPickfirstSelection() { . . . } |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )
GMT+8, 2024-5-7 07:24
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.