Author Topic: palette location - C#  (Read 8156 times)

0 Members and 1 Guest are viewing this topic.

Bryan Thatcher

  • Guest
palette location - C#
« on: July 19, 2012, 09:30:54 AM »
I'm using ToolPaletteManager to update the CatalogPath and LoadCatalogs. But the tool palette window is relocating/reseting to the center of the screen. How can I lock the palette down. Thanks. 

BlackBox

  • King Gator
  • Posts: 3770
Re: palette location - C#
« Reply #1 on: July 19, 2012, 12:39:47 PM »
Welcome to TheSwamp!

Perhaps this document will be of use, particularly the section on 'Restoring User Settings' (page 10):

AU 2007 CP205-2, Creating a Docking Palette for AutoCAD with VB.NET
"How we think determines what we do, and what we do determines what we get."

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: palette location - C#
« Reply #2 on: December 03, 2013, 03:27:56 AM »
I have a hope it will be useful too:
Code - C#: [Select]
  1. //*****************************************************************************
  2. // WARNING! The sequence of the values assignment for the properties influences
  3. // behavior of Palette! It is necessary to set up properties in the order provided
  4. // below.
  5.  
  6. // 1. Set the icon
  7. palette_set.Icon = Icon.FromHandle(Resource1.SheetSet.GetHicon());
  8.  
  9. // Display the palette set.
  10. // 2. The palette shall be visible before setting the side of the Docking or Docking status.
  11. palette_set.KeepFocus = true;
  12. palette_set.Visible = true;
  13.  
  14. palette_set.Style = Win.PaletteSetStyles.ShowCloseButton |
  15.         Win.PaletteSetStyles.ShowPropertiesMenu |
  16.         Win.PaletteSetStyles.ShowAutoHideButton;
  17.  
  18. // Let the palette set can be docked only to left\right by the user.
  19. // 3. The side (sides) of the Docking must to be specified before changing of the Docking state.
  20. palette_set.DockEnabled = Win.DockSides.Left | Win.DockSides.Right;
  21.  
  22. // The Docking status at the starting time  of displaying of the palette.
  23. // 4. Set the Docking status.
  24. palette_set.Dock = Win.DockSides.None;
  25.  
  26. // Position of the top left corner of palette
  27. palette_set.Location = new Point(150, 200);
  28.  
  29. palette_set.Size = new Size(400, 600);
  30. palette_set.TitleBarLocation = Win.PaletteSetTitleBarLocation.Left;
  31. palette_set.Opacity = 100;                      
  32.  
  33. // 5. Don't forget to do it at the end
  34. palette_set.RecalculateDockSiteLayout();
  35.  
  36. // P.S. Also you can reed this (russian text): http://adn-cis.org/forum/index.php?topic=364.0
  37. //*****************************************************************************

Best regards.
« Last Edit: December 04, 2013, 12:20:13 AM by Andrey Bushman »

Jeff H

  • Needs a day job
  • Posts: 6150
Re: palette location - C#
« Reply #3 on: December 06, 2013, 03:07:34 AM »
To remember the location you need to use constructor that takes a GUID and AutoCAD will store information in the registry for you.

Use the one that does not accept a guid until you are happy with it and if you make changes sometimes you will have to change GUID in constructor to make it work correctly.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: palette location - C#
« Reply #4 on: December 06, 2013, 03:24:28 AM »
To remember the location you need to use constructor that takes a GUID and AutoCAD will store information in the registry for you.

Use the one that does not accept a guid until you are happy with it and if you make changes sometimes you will have to change GUID in constructor to make it work correctly.
Yes, I know. I use it here :)

Jeff H

  • Needs a day job
  • Posts: 6150
Re: palette location - C#
« Reply #5 on: December 06, 2013, 04:46:45 PM »

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: palette location - C#
« Reply #6 on: December 06, 2013, 10:39:51 PM »
Thank you, Jeff! It is very interesting and useful.

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: palette location - C#
« Reply #7 on: December 09, 2013, 07:52:50 AM »
Wish this worked with a WPF form
Storing Dialog or Forms settings with UserConfigurationManager

Why couldn't you?  Just use the same code in a Loaded and UnLoaded event handler.
Revit 2019, AMEP 2019 64bit Win 10

Jeff H

  • Needs a day job
  • Posts: 6150
Re: palette location - C#
« Reply #8 on: December 09, 2013, 11:04:14 AM »
Doesn't persist for me.

Have looked into it and checked registry.

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: palette location - C#
« Reply #9 on: December 09, 2013, 01:19:20 PM »
Apologizes to the OP for some what hijacking this thread.  My example of WPF/UserConfigurationManager.

Code - Text: [Select]
  1. <Window x:Class="WpfApplication3.TestWindow"
  2.         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3.         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4.         Title="TestWindow" Height="300" Width="300" Loaded="WindowLoaded" Unloaded="WindowUnloaded">
  5.     <Grid>
  6.         <StackPanel Orientation="Vertical">
  7.             <CheckBox Content="CheckBox" HorizontalAlignment="Center" IsChecked="{Binding IsChecked}" />
  8.             <TextBox Height="23" Text="{Binding Text}" Width="120" HorizontalAlignment="Center"/>
  9.         </StackPanel>
  10.     </Grid>
  11. </Window>
  12.  

Code - C#: [Select]
  1. using System.ComponentModel;
  2. using System.Windows;
  3. using Application = Autodesk.AutoCAD.ApplicationServices.Core.Application;
  4.  
  5. namespace WpfApplication3
  6. {
  7.     /// <summary>
  8.     /// Interaction logic for TestWindow.xaml
  9.     /// </summary>
  10.     public partial class TestWindow : INotifyPropertyChanged
  11.     {
  12.         private bool _isChecked;
  13.         public bool IsChecked
  14.         {
  15.             get { return _isChecked; }
  16.             set
  17.             {
  18.                 _isChecked = value;
  19.                 RaisePropertyChanged("IsChecked");
  20.             }
  21.         }
  22.  
  23.         private string _text;
  24.         public string Text
  25.         {
  26.             get { return _text; }
  27.             set
  28.             {
  29.                 _text = value;
  30.                 RaisePropertyChanged("Text");
  31.             }
  32.         }
  33.  
  34.         public TestWindow()
  35.         {
  36.             InitializeComponent();
  37.             DataContext = this;
  38.         }
  39.  
  40.         private void WindowLoaded(object sender, RoutedEventArgs e)
  41.         {
  42.             var ucm = Application.UserConfigurationManager;
  43.             using (var section = ucm.OpenDialogSection(this))
  44.             {
  45.                 IsChecked = (bool) section.ReadProperty("IsChecked", false);
  46.                 Text = (string) section.ReadProperty("Text", string.Empty);
  47.             }
  48.         }
  49.  
  50.         private void WindowUnloaded(object sender, RoutedEventArgs e)
  51.         {
  52.             var ucm = Application.UserConfigurationManager;
  53.             using (var section = ucm.OpenDialogSection(this))
  54.             {
  55.                 section.WriteProperty("IsChecked", IsChecked);
  56.                 section.WriteProperty("Text", Text);
  57.             }
  58.         }
  59.  
  60.  
  61.         public event PropertyChangedEventHandler PropertyChanged;
  62.  
  63.         protected virtual void RaisePropertyChanged(string propertyName)
  64.         {
  65.             var handler = PropertyChanged;
  66.             if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
  67.         }
  68.     }
  69. }
  70.  

Code - C#: [Select]
  1. using Autodesk.AutoCAD.Runtime;
  2. using WpfApplication3;
  3. using Application = Autodesk.AutoCAD.ApplicationServices.Core.Application;
  4.  
  5. [assembly: CommandClass(typeof(Commands))]
  6.  
  7. namespace WpfApplication3
  8. {
  9.     class Commands
  10.     {
  11.         [CommandMethod("TESTDIALOG")]
  12.         public void TestDialog()
  13.         {
  14.             var dialog = new TestWindow();
  15.             Application.ShowModalWindow(Application.MainWindow.Handle, dialog, false);
  16.         }
  17.     }
  18. }
  19.  

I took a screenshot of my registry and the entry working as expected but I cannot post to photobucket from work.  So you'll have to take my word that it worked. :roll:
Revit 2019, AMEP 2019 64bit Win 10

Jeff H

  • Needs a day job
  • Posts: 6150
Re: palette location - C#
« Reply #10 on: December 09, 2013, 05:10:26 PM »
The only difference I can see is passing the handle in ShowModalWindow. Makes since it might need that, Did not have to pass it for a Windows form but will try that and see if it works.

Thanks.