Code Red > .NET

Saving and Restoring Palette Location

(1/1)

cmwade77:
I have managed to figure out how to make a tool palette based off of a very old PDF from 2007, but I want the tool palette to save the location, size, etc. and restore it. The old document is in vb .net, which I have converted to C# for most, but for some reason the saving and restoring of the position of the palette doesn't seem to be working, here is the code I have for this:


--- Code - C#: ---using System;using System.Drawing;using Autodesk.AutoCAD.DatabaseServices;using Autodesk.AutoCAD.EditorInput;using Autodesk.AutoCAD.Runtime;using Autodesk.AutoCAD.Windows;using Microsoft.VisualBasic.CompilerServices;using Autodesk.AutoCAD.Geometry;using Autodesk.AutoCAD.ApplicationServices;using System.Windows.Media.Imaging;using BDuct_Global;  namespace BDuct{    public class Commands : IExtensionApplication    {                [CommandMethod("BDUCT_INSERT_BLOCK")]        public void BDuct_Insert_Block()        {            string BlockName = GlobalVariables.Duct_Shape + "_";                        switch (GlobalVariables.SelectedButton.Name)            {                case "Duct_Main":                    BlockName = BlockName + "DUCT";                break;                default:                    break;             }            AutoCADFunctions.InsertBlock(BlockName);        }         [CommandMethod("BDuct")]        public void BDuct()        {            if (GlobalVariables.ps == null)            {                GlobalVariables.ps = new PaletteSet("BDuct", new Guid("{ECBFEC73-9FE4-4aa2-8E4B-3068E94A2BFA}"));                GlobalVariables.ps.Style = PaletteSetStyles.ShowPropertiesMenu | PaletteSetStyles.ShowAutoHideButton | PaletteSetStyles.ShowCloseButton;                 // ps.Icon = GetEmbeddedIcon("Example1.gold_1_32.ico")                 GlobalVariables.ps.MinimumSize = new Size(412, 629);                var myPalette = GlobalVariables.MainWindow;                myPalette.TableLayoutPanel1.BackColor = Color.FromArgb(59, 68, 83);                myPalette.GroupBox1.BackColor = Color.FromArgb(59, 68, 83);                myPalette.BackColor = Color.FromArgb(59, 68, 83);                myPalette.Panel10.BackColor = Color.FromArgb(59, 68, 83);                GlobalVariables.ps.Add("BDuct", myPalette);                GlobalVariables.ps.KeepFocus = false;                GlobalVariables.ps.Visible = true;                            }            else if (GlobalVariables.ps.Visible == false)            {                GlobalVariables.ps.Visible = true;            }        }         public void Initialize()        {            // Throw New NotImplementedException()        }         public void Terminate()        {            // Throw New NotImplementedException()        }        private static void ps_Load(object sender, PalettePersistEventArgs e)        {            // demo loading user data             double a = Conversions.ToDouble(e.ConfigurationSection.ReadProperty("BDuct", 22.3d));        }        private static void ps_Save(object sender, PalettePersistEventArgs e)        {            // demo saving user data             e.ConfigurationSection.WriteProperty("BDuct", 32.3d);        }             }}
I would appreciate it if anyone has any ideas on this.

MickD:
In the past I have used the application's Properties.Settings to save and recall this info, or you could save it somewhere in your app when you fire it up but that won't persist unless you write it out to file.

hth :)

It's Alive!:
Aren’t palettes persisted somewhere in the user profile, under the Guid?

MickD:
there's even a spot to save this info :)

gile:
In the first releases of AutoCAD .NET the PalettSet class was sealed. Nowadays it is a better practice to create a class that derives from PaletteSet to define the appearance and controls contained in the palette set. You can have a look at this example.
As said upper, if you make changes to the paletteSet display, you should change the GUID also.

Navigation

[0] Message Index

Go to full version