_DMxDrawX::RegistUserCustomCommand
向CAD控件注册一个命令,用户在命令行输入命令名这个字符串,就会触发执行命令事件 命令事件的id就是该注册时的id值,成功返回true。详细说明如下:
| 参数 | 说明 |
|---|---|
|
BSTR pszCommandName |
命令名称 |
|
LONG lId |
命令id |
在面代码在控件加载完成后,注册一个MyTest命令。
private void axMxDrawX1_InitComplete(object sender, EventArgs e)
{
// 在控件加载完成后,注册一个MyTest命令,命令id 55.
axMxDrawX1.RegistUserCustomCommand("MyTest", 55);
}响应控件命令执行事件:

private void axMxDrawX1_ImplementCommandEvent(object sender, AxMxDrawXLib._DMxDrawXEvents_ImplementCommandEventEvent e)
{
if (e.iCommandId == 55)
{
MessageBox.Show("执行MyTest命令");
}
命令行输入 MyTest的效果:

在代码中也可以如下方式调用命令:
axMxDrawX1.SendStringToExecute("MyTest");
调用RegistUserCustomCommand函数注册一个命令时,如果系统中已经了该命令,它会覆盖该命令。
下面演示,一下如何重写打印命令
A. 查看打印命令名
点工具条上的打印按钮,在命令行提示的命令字符串,就是打印命令名,如上图:

B. 注册打印命令为自定义命令
axMxDrawX1.RegistUserCustomCommand("Plot", 55);
C. 响应自定义命令
private void axMxDrawX1_ImplementCommandEvent(object sender, AxMxDrawXLib._DMxDrawXEvents_ImplementCommandEventEvent e)
{
if (e.iCommandId == 55)
{
MessageBox.Show("执行打印命令 Polt");
}
D.运行效果如下:
