Author Topic: Removing and re-adding to PaletteSet  (Read 1683 times)

0 Members and 1 Guest are viewing this topic.

cincir

  • Guest
Removing and re-adding to PaletteSet
« on: April 17, 2016, 06:41:58 PM »
Hi everyone,

I have a static usercontrol and a paletteset. when I add usercontrol to paletteset and remove it and add it again I can not see the palette. any idea why? is it something about defining a parent at first and can't change it at the second add.

Thanks.

Atook

  • Swamp Rat
  • Posts: 1029
  • AKA Tim
Re: Removing and re-adding to PaletteSet
« Reply #1 on: April 17, 2016, 10:57:32 PM »
Hard to say without seeing your code. Is the control the single control on the palette? Maybe you need to re-instantiate the palette after removing the control.

Why remove and add the control back to the palette?

cincir

  • Guest
Re: Removing and re-adding to PaletteSet
« Reply #2 on: April 18, 2016, 08:04:57 AM »
Atook you got me wrong. I am talking about a whole UserControl not a single control in a UserControl. To clarify please check the code below ;

Code: [Select]
        private static PaletteSet paletteSet;
        private static Palette palette;
        private static UserControl1 userControl;


        public PaletteDemo() //this is constructor
        {
            if (paletteSet== null)
            {
                paletteSet= new PaletteSet("MyPaletteSet", new Guid("81BE7D63-5FA9-4CA5-9418-7830CA53B766"));
                paletteSet.Dock = DockSides.None;
                paletteSet.DockEnabled = DockSides.None;
            }
            if (userControl== null)
            {
                userControl = new UserControl1();
            }
        }

        [CommandMethod("AttachPalette")]
        public void AttachPalette()
        {
            if (palette== null)
            {
                palette = paletteSet.Add("Control1", userControl);
            }
            paletteSet.Visible = true;

        }

        [CommandMethod("DetachPalette")]
        public void DetachPalette()
        {
            if (palette != null)
            {
                int i = 0;
                for (i = 0; i < paletteSet.Count; i++)
                {
                    if (paletteSet[i].Name == "Control1")
                    {
                        break;
                    }
                }

                if (i != paletteSet.Count)
                {
                    paletteSet.Remove(i);
                    palette = null;
                }
            }

            if (paletteSet.Count == 0)
            {
                paletteSet.Visible = false;
            }
        }

after loading this code with netload and type the commands:

AttachPalette //No problem shows the PaletteSet with the Palette hosting UserControl1
DetachPalette //No problem hides the PaletteSet
AttachPalette //Problem. Showing an empty PaletteSet


Atook

  • Swamp Rat
  • Posts: 1029
  • AKA Tim
Re: Removing and re-adding to PaletteSet
« Reply #3 on: April 18, 2016, 06:00:36 PM »
Looking at your code, nothing jumps out at me.

Try dropping a breakpoint on

Code - C#: [Select]
  1.  palette = paletteSet.Add("Control1", userControl);

in AttachPalette and check to see if the variable userControl needs to be re-instantiated the second time around.


CADbloke

  • Bull Frog
  • Posts: 342
  • Crash Test Dummy
Re: Removing and re-adding to PaletteSet
« Reply #4 on: April 19, 2016, 05:01:12 AM »
Working from hazy memory ... try userControl.Invalidate() the control to refresh its contents. I think the Windows mechanism needs a kick in the pants to now something has changed in the layout. If it's not .Invalidate() it's something like that. Or not.

cincir

  • Guest
Re: Removing and re-adding to PaletteSet
« Reply #5 on: April 19, 2016, 06:25:50 AM »
CADbloke I tried Invalidate(), Refresh(), CreateGraphics() but no chance.