Skip to content

Dynamically adding new panels

New Discussion
Vern
Vern asked on Sep 15, 2011 8:49 PM

Application has several panels some or all of which the user may choose to have on his screen. It is very much like Visual Studio in that user may choose their own combination of panels, their layout (docking) etc. He can choose which panel to keep closed. Each open panel has one user control filling it.

When the application restarts, I want to restore the last settings i.e. the panel docking, the controls inside them. very much like Visual Studio

I am wondering :

1. how would the application know which panels were open last time and where they were placed by the user? So, panel x may have been docked to top by one user and while docked bottom by another use and a third user may have closed it completely. In other words, at app start time, I need to know which panels to open and where to dock them. I am hoping the DockManager would provide some help with that. Any samples code available? 

2. once I determine the panel that are to be opened, I would then instantiate the control and add it to the panel? Is that the approach you would recommend. I know this is not an Infragistics question per se but I am hoping there is something in the toolset that I may be able to exploit.

 Thanks!

Sign In to post a reply

Replies

  • 0
    Mike Dour
    Mike Dour answered on Jul 17, 2008 2:32 PM

    [quote user="vrn"]1. how would the application know which panels were open last time and where they were placed by the user? So, panel x may have been docked to top by one user and while docked bottom by another use and a third user may have closed it completely. In other words, at app start time, I need to know which panels to open and where to dock them. I am hoping the DockManager would provide some help with that. Any samples code available?  [/quote] 

    The UltraDockManager has SaveAs… and LoadFrom… method which allow you to save and load layout files. This will do exactly what you ask in your first question. You would typically want to save the layout file in the FormClosed event and load it if it exists at the end of the constructor or in the Load event of the Form. The Docking Demo sample uses the layout files, but in a slightly different way. It allows you to save and load layout files from a menu. It also saves the layout when the program loads and allows the user to reset the layout by loading in the originally saved layout.

    [quote user="vrn"]2. once I determine the panel that are to be opened, I would then instantiate the control and add it to the panel? Is that the approach you would recommend. I know this is not an Infragistics question per se but I am hoping there is something in the toolset that I may be able to exploit.[/quote]

    I haven't tried using it with loading layout files yet, but there is an InitializePane event which you could use to only load a control once the pane is first shown.

    • 0
      Vern
      Vern answered on Jul 17, 2008 3:31 PM

      [quote user="[Infragistics] Mike Dour"]The UltraDockManager has SaveAs… and LoadFrom… method which allow you to save and load layout files. This will do exactly what you ask in your first question. You would typically want to save the layout file in the FormClosed event and load it if it exists at the end of the constructor or in the Load event of the Form. The Docking Demo sample uses the layout files, but in a slightly different way. It allows you to save and load layout files from a menu. It also saves the layout when the program loads and allows the user to reset the layout by loading in the originally saved layout.[/quote] 

      Thanks Mike! When you say "Docking Demo", is that on the Infragistics sample code installed with the toolkit or something on the website? If latter, can you provide link?

      [quote user="[Infragistics] Mike Dour"]I haven't tried using it with loading layout files yet, but there is an InitializePane event which you could use to only load a control once the pane is first shown.[/quote]

      The requirement involves having to show a new panel for each user action and fill it with a user control. So, for say 15 user actions, I will need 15 different user controls. I have two choices

      1. Design 15 different panels and fill the control at InitializePanel time.

      2. Dynamically generate the panels and then fill it with the controls

      The advantage to the second approach is its scalability. If the application later needs to support 5  new user controls , none of the layout code needs to change.

       Do you think I can achieve #2 and still save the layout? So, one user may open User Control 1(UC1), UC10 and UC11 in three dynamically generated panels. While in another scenario it was UC2, UC4 in two dynamically generated panels. Since these controls are coming up in dynamically generated panel, what would the DockManager save for the two users? Would it know how many panels to be generated at initialization, where to dock those and which controls are to be placed on those panels?

      Thanks!

      • 0
        Mike Dour
        Mike Dour answered on Jul 18, 2008 2:34 PM

        [quote user="vrn"]Thanks Mike! When you say "Docking Demo", is that on the Infragistics sample code installed with the toolkit or something on the website? If latter, can you provide link? [/quote]

        That is one of the installed samples. I'm not sure where it is located, but it might be located in the toolbars section.

        [quote user="vrn"]Do you think I can achieve #2 and still save the layout? So, one user may open User Control 1(UC1), UC10 and UC11 in three dynamically generated panels. While in another scenario it was UC2, UC4 in two dynamically generated panels. Since these controls are coming up in dynamically generated panel, what would the DockManager save for the two users? Would it know how many panels to be generated at initialization, where to dock those and which controls are to be placed on those panels? [/quote]

        The dock manager would be able to do this if the controls were somewhere on the Form when the LoadFrom… method was called. When you load a layout file, the dock manager will initialize a DockableControlPane with the settings it was saved with. Then it will look at the controls on the form and try to find a control with the same Name property value as the control that was docked in the pane. If one is not found, the pane is removed. You will need to save another file with the layout file. This file will indicate to you which controls should be initialized and added to the form before loading the dock manager's layout file.

      • 0
        Vern
        Vern answered on Jul 21, 2008 7:14 AM

        [quote user="[Infragistics] Mike Dour"]The dock manager would be able to do this if the controls were somewhere on the Form when the LoadFrom… method was called. When you load a layout file, the dock manager will initialize a DockableControlPane with the settings it was saved with. [/quote]

        Mike, From what you are saying it seem the key is to make application know which controls were open when it last closed. That way, if the application instantiate those controls at LoadForm time, the dockmanage would do the needful to put it on the correct pane. Do you agree with conclusion?

         Second question, my entire application is developed as a user control. The dock manager is on the user control instead of the form. So what you said about "LoadForm" is applicable if the dockmanager is on the Form. What is event that I should be concerned about when dock manager is on the user control?

         Thanks!

      • 0
        Mike Dour
        Mike Dour answered on Jul 21, 2008 2:18 PM

        [quote user="vrn"]Mike, From what you are saying it seem the key is to make application know which controls were open when it last closed. That way, if the application instantiate those controls at LoadForm time, the dockmanage would do the needful to put it on the correct pane. Do you agree with conclusion?[/quote]

        Yes, that is correct.

        [quote user="vrn"]Second question, my entire application is developed as a user control. The dock manager is on the user control instead of the form. So what you said about "LoadForm" is applicable if the dockmanager is on the Form. What is event that I should be concerned about when dock manager is on the user control?[/quote]

        Yes, it will work with a user control as well. Also, I wasn't referring to anything called LoadForm, I was talking about the LoadFrom… methods. The dock manager has LoadFromXml and LoadFromBinary methods which load a layout file depending on what format it was saved in.

      • 0
        Vern
        Vern answered on Jul 22, 2008 1:25 PM

        Thank for the help so far Mike. Your suggestions as well the Docking Demo you suggested helped me get a whole lot further.

        – Currently I have this simple code in my play app that generates a new control at runtime and TRIES to dock it as part of a existing tab group of right-docked controls. Instead of that becoming part of the tabgroup, the userControl3 just becomes a new panel docked right but sitting side-by-side to that tab group. How do I make it part of that tab group of right-docked controls?

        UserControl1 userControl3 = new UserControl1();

        ultraDockManager1.DockControls(

        new Control[1] { userControl3 }, Infragistics.Win.UltraWinDock.DockedLocation.DockedRight, Infragistics.Win.UltraWinDock.ChildPaneStyle.TabGroup);

        – I see code snippet on the forum where docking is done to a named dockarea i.e. referencing DockArea by its key. It seems like a great way to logically group controls but I do not know how to use it.

      • 0
        Mike Dour
        Mike Dour answered on Jul 22, 2008 3:08 PM

        Try using the following code:

        this.ultraDockManager1.BeginUpdate();

        bool paneAddedToGroup = false;

        foreach ( DockAreaPane dockArea in this.ultraDockManager1.DockAreas )
        {
         if ( dockArea.DockedLocation != DockedLocation.DockedRight )
          continue;

         DockableControlPane controlPane = this.ultraDockManager1.ControlPanes.Add( this.userControl3 );
         dockArea.Panes.Add( controlPane );
         paneAddedToGroup = true;
         break;
        }

        if ( paneAddedToGroup == false )
        {
         this.ultraDockManager1.DockControls(
          new Control[ { this.userControl3 },
          DockedLocation.DockedRight,
          ChildPaneStyle.TabGroup );
        }

        this.ultraDockManager1.EndUpdate();

        To use a named dock area, you can set the Key property of a dock area. Then when you access the DockAreas collection of the dock manager, you can specify that key instead of an index when trying to get a dock area from the collection.

      • 0
        Vern
        Vern answered on Jul 24, 2008 5:08 AM

        – Once the user has closed a docked pane by clicking on the "x", how can I bring it back programmatically? I read somewhere that I have do a Show() on the pane. In my current design, I am dropping controls directly onto the form. How do I determine the pane I need to Show()?  

        – When  the pane is restored programmatically, would it recover the last docking when it was closed?

        – Related to the first question, to find out which panes are not visible i.e. ones which are closed using the "x". I am guessing I need to iterate over some collection and check some property. I would like to know what that collection and property is.

        Thanks!

      • 0
        Amiram Korach
        Amiram Korach answered on Jul 24, 2008 6:32 AM

        I did something like that. (maybe there is a built-in feature for that, anyone?)

        My idea was to populate a menu with all the control names that docked. When the user clicked on a menu item, I get the control name from it and send it to this method:

        public void ShowListControl(Form ContainerForm, UltraDockManager DockManager, string controlName)

        {

        Control control = ContainerForm.Controls.Find(controlName, true).FirstOrDefault();if (control != null)

        {

        var controlPane = DockManager.ControlPanes[control];if (controlPane != null)

        {

        controlPane.Show();

        controlPane.Activate();

        }

        }

        else // If the control is floating, it cannot be found via the form

        {

        foreach (var controlPane in DockManager.ControlPanes)

        {

        if (controlPane.Control != null && controlPane.Control.Name == controlName)

        {

        controlPane.Show();

        controlPane.Activate();

        break;

        }

        }

        }

        }

      • 0
        Mike Dour
        Mike Dour answered on Jul 24, 2008 5:20 PM

        jct, You can try to assign each control pane a key that is the name of the control it hosts. Then you can just index into the dock manager's ControlPanes collection with the control name.

         

      • 0
        Mike Dour
        Mike Dour answered on Jul 24, 2008 5:19 PM

        [quote user="vrn"]Once the user has closed a docked pane by clicking on the "x", how can I bring it back programmatically? I read somewhere that I have do a Show() on the pane. In my current design, I am dropping controls directly onto the form. How do I determine the pane I need to Show()?  [/quote]

        Yes, the Show() method will show the pane again. You can give each control pane a Key which will help you identify each pane. When you are looking for the pane, you can access the dock manager's ControlPanes collection and index into it with the key of the pane you are looking for.

        [quote user="vrn"]When  the pane is restored programmatically, would it recover the last docking when it was closed?[/quote]

        Yes. The only exception to this is if the pane was unpinned and closed. When shown again, it would be pinned. This is how VS behaves and the dock manager duplicates this behavior.

        [quote user="vrn"]Related to the first question, to find out which panes are not visible i.e. ones which are closed using the "x". I am guessing I need to iterate over some collection and check some property. I would like to know what that collection and property is.[/quote]

        You can iterate over the ControlPanes collection of the dock manager to get all panes which have controls you have docked (all panes which aren't groups or dock area). On these panes you can get the Closed property to determine whether it is hidden or not. You can also set the Closed property to False to show a pane, but if the pane's parent pane were also closed, the pane would not show, whereas calling Show() will show any hidden parent panes as well.

      • 0
        Patrick McHargue
        Patrick McHargue answered on Sep 6, 2011 6:29 PM

        In this post, you say, "You will need to save another file with the layout file. This file will indicate to you which controls should be initialized and added to the form before loading the dock manager's layout file."

        What controls need to be saved?  I've tried this, saving the coltrol names, and re-initializing those same inds of controls with their previous names ('System.Windows.Forms.Panel' controls that were used) when the dock manager's 'SaveAs…' was called.

        Doesn't seem to work, though.

        Is there an example of how this should work?

         

        Pat


      • 0
        Mike Dour
        Mike Dour answered on Sep 15, 2011 8:49 PM

        You should save the state of any controls that need to be loaded into dock panes. Then, before you load the layout for the dock manager, you should create the controls (if they don't already exist), give them the same Name they had before, and reinitialize them with any state that you have saved. You must also add them somewhere in the control hierarchy of the Form (or UserControl) in which the UltraDockManager resides. I like to create a temporary Panel which is hidden for this purpose so you don't see any flicker on screen. I have attached a relatively simple sample which does this.

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Vern
Favorites
0
Replies
13
Created On
Sep 15, 2011
Last Post
14 years, 5 months ago

Suggested Discussions

Created by

Created on

Sep 15, 2011 8:49 PM

Last activity on

Sep 15, 2011 8:49 PM