Home / Community & Support / Knowledge Base / RadControls for WinForms / ToolStrip / Saving and loading the layout of RadToolStrip

Saving and loading the layout of RadToolStrip

Article Info

Rating: Not rated

Article information

Article relates to

 RadToolStrip for WinForms

Created by

 Boyko Markov

Last modified

 2008/12/08

Last modified by

 Boyko Markov


 
HOW TO

Save/Load RadToolStrip's layout

SOLUTION
  1. Create a new class that derives from RadToolStrip class.
  2. Create a SaveLayout method:

    C#
    public virtual void SaveLayout(string fileName) 
            { 
                string layoutOutput = ""
      
                ComponentXmlSerializer ser = new ComponentXmlSerializer(); 
      
                using (XmlTextWriter writer = new XmlTextWriter(fileName, Encoding.UTF8)) 
                { 
                    writer.Formatting = Formatting.Indented; 
                    writer.WriteStartElement("RadToolStrip"); 
                    ser.WriteObjectElement(writer, this); 
                } 
      
            }  


    VB .NET
    public virtual void SaveLayout(string fileName)  
            {  
                string layoutOutput = "";  
       
                ComponentXmlSerializer ser = new ComponentXmlSerializer();  
       
                using (XmlTextWriter writer = new XmlTextWriter(fileName, Encoding.UTF8))  
                {  
                    writer.Formatting = Formatting.Indented;  
                    writer.WriteStartElement("RadToolStrip");  
                    ser.WriteObjectElement(writer, this);  
                }  
       
            }   

     
  3. Create a LoadLayout method:

    C#      
    public virtual void LoadLayout(string fileName) 
            { 
                if (!File.Exists(fileName)) 
                { 
                    MessageBox.Show("file not found""Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 
                    return
                } 
      
                this.SuspendLayout(); 
      
                using (StreamReader sr = new StreamReader(fileName)) 
                { 
      
                    string layoutOutput = sr.ReadToEnd(); 
      
                    ComponentXmlSerializer ser = new ComponentXmlSerializer(); 
      
                    using (StringReader reader = new StringReader(layoutOutput)) 
                    { 
                        using (XmlTextReader textReader = new XmlTextReader(reader)) 
                        { 
                            textReader.Read(); 
                            ser.ReadObjectElement(textReader, this); 
                        } 
                    } 
      
      
                } 
      
                this.ResumeLayout(); 
            }  


    VB .NET
    public virtual void LoadLayout(string fileName)  
            {  
                if (!File.Exists(fileName))  
                {  
                    MessageBox.Show("file not found""Error", MessageBoxButtons.OK, MessageBoxIcon.Error);  
                    return;  
                }  
       
                this.SuspendLayout();  
       
                using (StreamReader sr = new StreamReader(fileName))  
                {  
       
                    string layoutOutput = sr.ReadToEnd();  
       
                    ComponentXmlSerializer ser = new ComponentXmlSerializer();  
       
                    using (StringReader reader = new StringReader(layoutOutput))  
                    {  
                        using (XmlTextReader textReader = new XmlTextReader(reader))  
                        {  
                            textReader.Read();  
                            ser.ReadObjectElement(textReader, this);  
                        }  
                    }  
       
       
                }  
       
                this.ResumeLayout();  
            }   
  4. To save or load the layout you need to specify the full path of the file and its name.

    To save the layout:

    C#   
     string s = "default.xml";       
     this.radToolStrip1.SaveLayout(s); 

    VB .NET
     string s = "default.xml";        
     this.radToolStrip1.SaveLayout(s);  

    To load the layout:

    C#
     string s = "default.xml"
     this.radToolStrip1.LoadLayout(s); 

    VB .NET
     string s = "default.xml";  
     this.radToolStrip1.LoadLayout(s);  

Comments

There are no comments yet.
If you'd like to comment on this KB article, please, send us a Support Ticket.
Thank you!

Please Sign In to rate this article.