在Option对话框上添加选项卡的有效方法
AutoCAD .NET TabbedDialogExtension – Sample ImplementationAutoCAD .NET provides a means to extend the Options dialog through the TabbedDialogExtension class. In this article, we will be demonstrating how to do so with C# and AutoCAD .NET API. It is always good to start with some cool, concise and still full sample code. Here it is:using System;
using System.Text;
using System.Linq;
using System.Xml;
using System.Reflection;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media.Imaging;
using System.Windows.Forms;
using System.IO;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Windows;
using AcadApplication = Autodesk.AutoCAD.ApplicationServices.Application;
using AcadDocument = Autodesk.AutoCAD.ApplicationServices.Document;
using AcadWindows = Autodesk.AutoCAD.Windows;
namespace AcadNetAddinWizard_Namespace
{
public class TabbedDialogExtensioner
{
public void TestTabbedDialogExtensioner_Method()
{
TabbedDialogExtensioner eventManager = new TabbedDialogExtensioner();
eventManager.Register();
}
public void Register()
{
AcadApplication.DisplayingOptionDialog += new TabbedDialogEventHandler(AcadApplication_DisplayingOptionDialog);
}
void AcadApplication_DisplayingOptionDialog(object sender, TabbedDialogEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nDisplayingOptionDialog\n");
TabbedDialogExtension tabDiaExt = new TabbedDialogExtension(new UserControl1(), okCallback, cancelCallback, helpCallback, applyCallback);
e.AddTab("TabbedDialogExtensioner_TabName", tabDiaExt);
}
private void okCallback()
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nTabbedDialogExtension OK pressed.\n");
}
private void cancelCallback()
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nTabbedDialogExtension Cancel pressed.\n");
}
private void helpCallback()
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nTabbedDialogExtension Help pressed.\n");
}
private void applyCallback()
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nTabbedDialogExtension Apply pressed.\n");
}
}
}Since we are going to add one more tab to the AutoCAD Options dialog (the API term Tabbed Dialog), we need to prepare a UserControl beforehand as required by the constructor of the TabbedDialogExtension class. Our user control looks like the following:
http://spiderinnet1.typepad.com/.a/6a0153928ee38e970b0163026d02a3970d-800wi
It looks like what it really is and nothing is bad behind the scene though not exactly as the default auto-generated code:using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace AcadNetAddinWizard_Namespace
{
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
public string StringInput { get { return textBox1.Text; } set { textBox1.Text = value; } }
public bool Check1 { get { return checkBox1.Checked; } set { checkBox1.Checked = value; } }
public bool Radio1 { get { return radioButton1.Checked; } set { radioButton1.Checked = value; } }
public bool Radio2 { get { return radioButton2.Checked; } set { radioButton2.Checked = value; } }
public bool Radio3 { get { return radioButton3.Checked; } set { radioButton3.Checked = value; } }
public int ListSeletedIndex { get { return listBox1.SelectedIndex; } set { listBox1.SelectedIndex = value; } }
}
}
The extra behind of the scene work is actually to make the communication better between the Options dialog and the user control as demonstrated next.
After the command TestLongTransManagerEvents is run, one more tab will be added to the AutoCAD Options dialog like:
http://spiderinnet1.typepad.com/.a/6a0153928ee38e970b016763615917970b-800wi
If the input is changed or any options have been changed in the tab and the OK button of the Options dialog is clicked, the command line window will report something back:
Command: TestTabbedDialogExtensioner
Command: options
DisplayingOptionDialog
TabbedDialogExtension Help pressed.
StringInput: Hi buddies! Check1: False Radio1: True Radio2: False
Radio3: False ListSelectedIndex: 4
TabbedDialogExtension OK pressed.
StringInput: Hi buddies! Check1: False Radio1: False Radio2:
False Radio3: True ListSelectedIndex: 1
Command:
OPTIONS
DisplayingOptionDialog
TabbedDialogExtension Cancel pressed.
StringInput: Hey guys!Check1: TrueRadio1: False Radio2: False Radio3:
True ListSelectedIndex: 4.
The leading edge AutoCAD .NET Addin Wizard (AcadNetAddinWizard)provides an Options Dialog Extensioner to help implement the TabbedDialogExtension automatically, quickly, flexibly and reliably.
不错,好东西啊 楼主有没有操作现有选项卡的例子呢? 比如修改文件选项卡里面的 支持目录、信任位置等等。。目前我所知道的方式有 获取Preferences对象 COM类 的不知道楼主有更科学的方法吗
页:
[1]