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!
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.
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
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.
vrn said: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()?
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.
vrn said:When the pane is restored programmatically, would it recover the last docking when it was closed?
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.
vrn said: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.
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.
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