明经CAD社区

 找回密码
 注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 311|回复: 2

[界面] 在Option对话框上添加选项卡的有效方法

[复制链接]
发表于 2018-4-28 20:36 | 显示全部楼层 |阅读模式
AutoCAD .NET TabbedDialogExtension – Sample Implementation
               

                                       
AutoCAD .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:
  1. using System;
  2. using System.Text;
  3. using System.Linq;
  4. using System.Xml;
  5. using System.Reflection;
  6. using System.ComponentModel;
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. using System.Windows;
  10. using System.Windows.Media.Imaging;
  11. using System.Windows.Forms;
  12. using System.IO;
  13. using Autodesk.AutoCAD.ApplicationServices;
  14. using Autodesk.AutoCAD.DatabaseServices;
  15. using Autodesk.AutoCAD.Runtime;
  16. using Autodesk.AutoCAD.EditorInput;
  17. using Autodesk.AutoCAD.Geometry;
  18. using Autodesk.AutoCAD.Windows;
  19. using AcadApplication = Autodesk.AutoCAD.ApplicationServices.Application;
  20. using AcadDocument = Autodesk.AutoCAD.ApplicationServices.Document;
  21. using AcadWindows = Autodesk.AutoCAD.Windows;
  22. namespace AcadNetAddinWizard_Namespace
  23. {
  24.     public class TabbedDialogExtensioner
  25.     {
  26.         [CommandMethod("TestTabbedDialogExtensioner")]
  27.         public void TestTabbedDialogExtensioner_Method()
  28.         {
  29.             TabbedDialogExtensioner eventManager = new TabbedDialogExtensioner();
  30.             eventManager.Register();
  31.         }
  32.         public void Register()
  33.         {
  34.             AcadApplication.DisplayingOptionDialog += new TabbedDialogEventHandler(AcadApplication_DisplayingOptionDialog);
  35.         }
  36.         void AcadApplication_DisplayingOptionDialog(object sender, TabbedDialogEventArgs e)
  37.         {
  38.             AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nDisplayingOptionDialog\n");
  39.             TabbedDialogExtension tabDiaExt = new TabbedDialogExtension(new UserControl1(), okCallback, cancelCallback, helpCallback, applyCallback);
  40.             e.AddTab("TabbedDialogExtensioner_TabName", tabDiaExt);
  41.         }
  42.         private void okCallback()
  43.         {
  44.             AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nTabbedDialogExtension OK pressed.\n");
  45.         }
  46.         private void cancelCallback()
  47.         {
  48.             AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nTabbedDialogExtension Cancel pressed.\n");
  49.         }
  50.         private void helpCallback()
  51.         {
  52.             AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nTabbedDialogExtension Help pressed.\n");
  53.         }
  54.         private void applyCallback()
  55.         {
  56.             AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nTabbedDialogExtension Apply pressed.\n");
  57.         }
  58.     }
  59. }
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:

It looks like what it really is and nothing is bad behind the scene though not exactly as the default auto-generated code:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. namespace AcadNetAddinWizard_Namespace
  10. {
  11.     public partial class UserControl1 : UserControl
  12.     {
  13.         public UserControl1()
  14.         {
  15.             InitializeComponent();
  16.         }
  17.         public string StringInput { get { return textBox1.Text; } set { textBox1.Text = value; } }
  18.         public bool Check1 { get { return checkBox1.Checked; } set { checkBox1.Checked = value; } }
  19.         public bool Radio1 { get { return radioButton1.Checked; } set { radioButton1.Checked = value; } }
  20.         public bool Radio2 { get { return radioButton2.Checked; } set { radioButton2.Checked = value; } }
  21.         public bool Radio3 { get { return radioButton3.Checked; } set { radioButton3.Checked = value; } }
  22.         public int ListSeletedIndex { get { return listBox1.SelectedIndex; } set { listBox1.SelectedIndex = value; } }
  23.     }
  24. }

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:


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: True  Radio1: 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.







发表于 2018-10-1 22:57 | 显示全部楼层
不错,好东西啊
发表于 2018-10-1 23:00 | 显示全部楼层
楼主有没有操作现有选项卡的例子呢? 比如修改文件选项卡里面的 支持目录、信任位置等等。。目前我所知道的方式有 获取Preferences对象 COM类 的  不知道楼主有更科学的方法吗
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号  
©2000-2017 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2018-10-15 21:35 , Processed in 0.194513 second(s), 29 queries , Gzip On.

Powered by Discuz! X3.3

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表