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!
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?
Its possible, but it would need to be done manually. You could create an XML file where you store each configuration stream as a base 64 value in the file. Here is one way you could accomplish this for a toolbars manager and dock manager:
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_FormClosed( object sender, FormClosedEventArgs e ){ using ( XmlTextWriter writer = new XmlTextWriter( "config.xml", Encoding.Default ) ) { writer.WriteStartElement( "Config" ); writer.WriteStartElement( "ToolbarsConfig" );
using ( MemoryStream stream = new MemoryStream() ) { this.ultraToolbarsManager1.SaveAsBinary( stream, true );
byte[ buffer = stream.GetBuffer(); writer.WriteBase64( buffer, 0, buffer.Length ); }
writer.WriteEndElement();
writer.WriteStartElement( "DockConfig" );
using ( MemoryStream stream = new MemoryStream() ) { this.ultraDockManager1.SaveAsBinary( stream );
writer.WriteEndElement(); writer.WriteEndElement(); }}
private byte[ ReadBase64( XmlTextReader reader ){ List<byte> finalBuffer = new List<byte>(); byte[ buffer = new byte[ 1000 ];
while ( true ) { int bytesRead = reader.ReadBase64( buffer, 0, buffer.Length );
if ( bytesRead < buffer.Length ) { byte[ retValue = new byte[ finalBuffer.Count + bytesRead ];
Buffer.BlockCopy( finalBuffer.ToArray(), 0, retValue, 0, finalBuffer.Count ); Buffer.BlockCopy( buffer, 0, retValue, finalBuffer.Count, bytesRead );
return retValue; } else { finalBuffer.AddRange( buffer ); } }}
That saves all the layout settings in one XML file.However, there is a limitation: the individual layout is saved as Binary, and therefore unreadable.The ReadBase64 method is reading each binary block in the XML file.
Is it possible to use SaveAsXml on individual layout and combine them into the final XML file? and how can I read it back? 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.
So Base64 is necessary to implement as binary?
It all depends on whether you would like to use SaveAsBinary or SaveAsXml. The binary layout files are smaller in size but cannot be manually examined or edited. The XML layout files can be opened and edited by a developer in any xml editor.
Mike2008, I am going to take advantage of your thread to ask Mike Dour a related question. hope that is okay.
Mike Dour, what is the relative benefit of the Base 64 approach over XML? I am very new to this and hopefully not asking something very basic. It seems like using the XML would be advantageous for application support purposes.
Thanks!
If you use an XmlTextWriter like in the code I posted, I believe there is a WriteString method which will escape all control characters automatically. When you read back the string value with the XmlTextReader, the string will automatically be unescaped.