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!
vrn said: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?
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.
vrn said: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.
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.
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.
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?
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.
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?
vrn said: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?
That is one of the installed samples. I'm not sure where it is located, but it might be located in the toolbars section.
vrn said: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?
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.
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?
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.
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.
- 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.
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:
{
var controlPane = DockManager.ControlPanes[control];
controlPane.Show();
controlPane.Activate();
}
else // If the control is floating, it cannot be found via the form
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.