C# CAD PaletteSet.Dock停靠操作

在AutoCAD的.NET API中,PaletteSet对象(例如上述代码中的ps)还可以进行停靠操作。调用与Dock相关的方法通常会将调色板集停靠到应用程序主窗口的特定区域或边缘。

Autodesk.AutoCAD.Windows.PaletteSet ps = new PaletteSet("宗地属性面板");
ps.Dock(Autodesk.AutoCAD.Windows.DockSides.Left); // 将调色板集停靠在主窗口的左侧

DockSides枚举提供了几个选项来指定停靠的位置,包括Left、Right、Top和Bottom等。 

ps.DockEnabled 属性

ps.DockEnabled = true; // 允许调色板集进行停靠
ps.DockEnabled = false; // 禁止调色板集进行停靠
public static void DoIt()
        {
            if (ps==null)
            {
                //use constructor with Guid so that we can save/load user data
                ps = new Autodesk.AutoCAD.Windows.PaletteSet("Test Palette Set",new Guid("63B8DB5B-10E4-4924-B8A2-A9CF9158E4F6"));
                ps.Load+=new Autodesk.AutoCAD.Windows.PalettePersistEventHandler(ps_Load);
                ps.Save+=new Autodesk.AutoCAD.Windows.PalettePersistEventHandler(ps_Save);
                ps.Style = Autodesk.AutoCAD.Windows.PaletteSetStyles.NameEditable |
                    Autodesk.AutoCAD.Windows.PaletteSetStyles.ShowPropertiesMenu |
                    Autodesk.AutoCAD.Windows.PaletteSetStyles.ShowAutoHideButton |
                    Autodesk.AutoCAD.Windows.PaletteSetStyles.ShowCloseButton;
                ps.MinimumSize = new System.Drawing.Size(300,300);
                ps.Add("Test Palette 1", new TestControl());
            }
            bool b = ps.Visible;

            ps.Visible = true;
            Autodesk.AutoCAD.EditorInput.Editor e = AcadApp.DocumentManager.MdiActiveDocument.Editor;

            Autodesk.AutoCAD.EditorInput.PromptResult res = e.GetKeywords("Select a palette set option:","Opacity","TitleBarLocation","Docking");
            if (res.Status == Autodesk.AutoCAD.EditorInput.PromptStatus.OK)
            {
                switch (res.StringResult)
                {
                    case "Opacity":
                        Autodesk.AutoCAD.EditorInput.PromptIntegerResult resInt;
                        do
                        {
                            resInt = e.GetInteger("Enter opacity:");
                            if (resInt.Status != Autodesk.AutoCAD.EditorInput.PromptStatus.OK)
                                break;
                            if (resInt.Value>=0 && resInt.Value<=100)
                                break;
                            e.WriteMessage("Opacity must be between 0 and 100\n");
                        }
                        while (true);
                        ps.Opacity = resInt.Value;
                        break;
                    case "TitleBarLocation":
                        res = e.GetKeywords("Select titlebar location:","Left","Right");
                        if (res.Status == Autodesk.AutoCAD.EditorInput.PromptStatus.OK)
                            switch (res.StringResult)
                            {
                                case "Left":
                                    ps.TitleBarLocation = Autodesk.AutoCAD.Windows.PaletteSetTitleBarLocation.Left;
                                    break;
                                case "Right":
                                    ps.TitleBarLocation = Autodesk.AutoCAD.Windows.PaletteSetTitleBarLocation.Right;
                                    break;
                            }
                        break;
                    case "Docking":
                    {
                        res = e.GetKeywords("Choose a docking option:","None","Left","Right","Top","Bottom");
                        if (res.Status == Autodesk.AutoCAD.EditorInput.PromptStatus.OK)
                        {
                            switch (res.StringResult)
                            {
                                case "None":
                                    ps.Dock = Autodesk.AutoCAD.Windows.DockSides.None;
                                    break;
                                case "Left":
                                    ps.Dock = Autodesk.AutoCAD.Windows.DockSides.Left;
                                    break;
                                case "Right":
                                    ps.Dock = Autodesk.AutoCAD.Windows.DockSides.Right;
                                    break;
                                case "Top":
                                    ps.Dock = Autodesk.AutoCAD.Windows.DockSides.Top;
                                    break;
                                case "Bottom":
                                    ps.Dock = Autodesk.AutoCAD.Windows.DockSides.Bottom;
                                    break;
                            }
                        }
                        break;
                    }
                }
            }
        }

程序解读

这段C#代码定义了一个名为DoIt的静态公共方法,其功能是在AutoCAD环境中创建、显示并根据用户交互调整一个调色板集(PaletteSet)的属性。以下是详细解读:

  1. 首先检查变量ps是否为null,如果是,则初始化一个新的Autodesk.AutoCAD.Windows.PaletteSet对象,名称为"Test Palette Set",并关联一个Guid以保存和加载用户数据。

  2. 为调色板集注册两个事件处理器ps_Loadps_Save,分别用于在调色板集加载和保存时触发。

  3. 设置调色板集的样式,包括允许编辑名称、显示属性菜单、自动隐藏按钮和关闭按钮。

  4. 设置调色板集的最小尺寸为300x300像素,并向其中添加一个名为"Test Palette 1"的新控件(类型为TestControl)。

  5. 检查并确保调色板集可见(如果之前被隐藏,则将其设置为可见)。

  6. 获取当前活动文档的编辑器对象。

  7. 显示一个提示对话框,让用户选择调色板集的一个选项:"Opacity"、"TitleBarLocation"或"Docking"。

  8. 根据用户选择的选项执行以下操作:

    • 如果选择"Opacity",则循环获取用户输入的整数作为不透明度值(介于0到100之间),并将该值应用于调色板集的不透明度属性。
    • 如果选择"TitleBarLocation",再次提示用户从"Left"或"Right"中选择标题栏位置,并相应地设置调色板集的标题栏位置。
    • 如果选择"Docking",则提示用户选择停靠位置,并根据用户的选择将调色板集停靠在主窗口的左侧、右侧、顶部、底部或无停靠。

总之,这个方法是一个完整的调色板集管理单元,负责创建、展示以及根据用户的实时反馈来修改调色板集的各种视觉和布局特性。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值