I am trying to save the MDI state when closing the application and load it when opening. Like FireFox, it opens all the web pages last time when you close the application. I've noticed that UltraTabbedMdiManager have methods like SaveAsXml and LoadFromXml.What is contained in the saved XML file?
What do I need to do if I want to open the last visited pages like FireFox? Thanks.Mike
The XML file will contain all properties and values which are publicly exposed in the tabbed mdi manager. It is intended to save customizations the user might have made, through both the default UI, as well as any additional UI you have added to your application to give the user control over certain aspects of the tabbed mdi manager. One of the reasons to save and load this file would be to maintain the tab groups into which the user has organized the mdi child forms. However, loading the XML file will not open the forms which were previously opened. You must keep track of which forms were open when the XML file was saved and re-open them before loading the XML file.
>You must keep track of which forms were open when the XML file was saved and re-open them before loading the XML file.
So i guess i should save the open forms into a separate file, instead of messing this XML file.
In fact, all I want to save for each form is the file name to initialize it. Is it possible to tag objects (e.g., the list of file names in this case) to the UltraTabbedMdiManager? Is it worth doing that?
>to maintain the tab groups into which the user has organized the mdi child formsThe only think i can think of is to switch between normal MDI and tabbed MDI. Anything else user acn do to organize child forms?Thanks!
mike2008 said:In fact, all I want to save for each form is the file name to initialize it. Is it possible to tag objects (e.g., the list of file names in this case) to the UltraTabbedMdiManager? Is it worth doing that?
No, because the load operation would load in the tag values and try to find the mdi child forms all before returning. There would be no way to intervene after the tag values were loaded to open the forms before the load operation attempted to find them. I would recommend using a separate file for this.
mike2008 said:>to maintain the tab groups into which the user has organized the mdi child formsThe only think i can think of is to switch between normal MDI and tabbed MDI. Anything else user acn do to organize child forms?
Just like in VS, the user can drag the tabs down or to the side to form new tab groups. They can also form new tab groups by right-clicking the tab and selecting 'New Horizontal Tab Group' or 'New Vertical Tab Group'
I tried to save child MDI forms in a separate file and successfully load them within MainForm's OnLoad method.But the LoadTabbedMdiLayout does not seems to work, even if i put it after loading all the child MDI forms. Even worse, it messes up the layout.I also tried to put LoadTabbedMdiLayout in OnLayout method in the MainForm, and it behaves the same.
Do you have any idea what is going wrong? and how can i make this work?
Thanks.
I must apologize: I was thinking about how the dock manager loads the layout and I assumed the tabbed mdi manager worked the same way, so I am sorry for giving bad advice. I have checked with someone more familiar with this component, and there are properties and events built in specifically for what you are trying to do. Handle the StoreTab event on the tabbed mdi manager. When a tab is going to be serialized to the XML file, this event will be fired for each tab. In your case, when you handle this event, set the PersistedInfo of the tab for which the event is being fired to the file name associated with the tab. For deserialization, handle the RestoreTab event. This event will be fired for each tab which was serialized. In the handler, you can get the PersistedInfo for the tab and create a Form (or use an existing Form) to use for the tab. Set the Form on the Form property of the event arguments.
Another question: Our application uses different managers (Toolbar, Dock, and MDI), is it possible to save the setting in a single file instead of multiple ones.What is the industrial standard to do that?
vrn said:I am guessing because ReadBase64 is reading the next node and decoding it, the order of loading the controls is important? So it should be read in the same sequence that I saved it?
Yes, that is correct.
vrn said:Do you have suggestion on how I can make the loading sequence independent of the saving sequence? This can prove useful for my design where I am trying to make each component completely independent of the other. So each component should be able to figure out its own setting from the larger XML file.
Instead of using an XmlTextReader, you can try to implement something using an XmlDocument. Then each control can iterate the child nodes of the document and find the node with their stream name and just read in that node. Alternatively, you could keep the same approach and read in all streams and populate them into a Dictionary<string,Stream>, where the key is the stream name. Then when each control goes to load, they just access the dictionary with the name they are looking for.
Mike Dour"] My code snippet used an XmlTextReader, which just reads the nodes in order, so it did not need to specify the config file it was looking for. I could have put asserts before loading each stream to make sure the current node had the expected names before loading them.
My code snippet used an XmlTextReader, which just reads the nodes in order, so it did not need to specify the config file it was looking for. I could have put asserts before loading each stream to make sure the current node had the expected names before loading them.
Mike your code worked like a charm!
- I am guessing because ReadBase64 is reading the next node and decoding it, the order of loading the controls is important? So it should be read in the same sequence that I saved it?
- Do you have suggestion on how I can make the loading sequence independent of the saving sequence? This can prove useful for my design where I am trying to make each component completely independent of the other. So each component should be able to figure out its own setting from the larger XML file.
vrn said:Mike, In the above code snippet I think you meant to do something with ToolbarConfig and DockConfig since write it out at Form closure.
vrn said:Second questoin, I want to let users to save as many settings as they like. That way they can have multiple looks and layouts pre-defined and they can change it to any of them very quickly. When they load such a setting file, I would like each control to process its own settings by firing an event. What should I be sending as part of the event to the individual control so that the control can pick it up from there? Should I make the control get the XML stream, the complete binary or something else?
I would send the stream loaded from the file in the event args. Then the control can just pass that to its appropriate LoadFrom... method.
Mike Dour"] private void Form1_Load( object sender, EventArgs e ){ if ( File.Exists( "config.xml" ) == false ) return; using ( XmlTextReader reader = new XmlTextReader( "config.xml" ) ) { reader.ReadStartElement( "Config" ); using ( MemoryStream stream = new MemoryStream( this.ReadBase64( reader ) ) ) this.ultraToolbarsManager1.LoadFromBinary( stream ); using ( MemoryStream stream = new MemoryStream( this.ReadBase64( reader ) ) ) this.ultraToolbarsManager1.LoadFromBinary( stream ); }}
private void Form1_Load( object sender, EventArgs e ){ if ( File.Exists( "config.xml" ) == false ) return;
using ( XmlTextReader reader = new XmlTextReader( "config.xml" ) ) { reader.ReadStartElement( "Config" );
using ( MemoryStream stream = new MemoryStream( this.ReadBase64( reader ) ) ) this.ultraToolbarsManager1.LoadFromBinary( stream );
using ( MemoryStream stream = new MemoryStream( this.ReadBase64( reader ) ) ) this.ultraToolbarsManager1.LoadFromBinary( stream ); }}
Mike, In the above code snippet I think you meant to do something with ToolbarConfig and DockConfig since write it out at Form closure.
Mike Dour"] writer.WriteStartElement( "DockConfig" );
writer.WriteStartElement( "DockConfig" );
If you do not mind, can you add that code to snippet to help me understand how you use the stream to read individual settings
Second questoin, I want to let users to save as many settings as they like. That way they can have multiple looks and layouts pre-defined and they can change it to any of them very quickly. When they load such a setting file, I would like each control to process its own settings by firing an event. What should I be sending as part of the event to the individual control so that the control can pick it up from there? Should I make the control get the XML stream, the complete binary or something else?
Thanks!
It all depends on how you want to store the data. If you want to convert the bytes of the saved binary layout file to some other format, you can use that. I just used Base64 because it is the standard way to store binary data.