This is a migrated thread and some comments may be shown as answers.

Saving RadToolStrip and other questions

3 Answers 66 Views
Toolstrip (obsolete as of Q3 2010)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Haroon
Top achievements
Rank 1
Haroon asked on 17 Jan 2008, 11:08 AM

Hi,
I have few questions regarding RadToolStrip.
1. If the user remove all ToolStripItems from the RadToolStrip then the RadToolStrip disappears (Which is fine) But how if your RadToolStrip is not visible now how can the user again add ToolStripItem in the RadToolStrip at runtime.

2.How can I restrict a Particular ToolStripItem not to be removes not even when the user tries to do so from “Add or Remove Buttons à Customize”. Ideally if I don’t allow can ToolStripItem to be remove it should not even display in “Add or Remove Buttons à Customize” Panel.

3.When a user remove all RadButtonElement from a ToolStripItem then ideally the ToolStripItem should be removed automatically and if the user again add any of its RadButtonElement then the ToolStripItem should reappear.

4.How can I save whole RadToolStrip (Its ToolStripItem, their location and RadButtonElement) so that if any user preferences should be saved.

P.S. I am working in VB 2005 enviroment

Regards,
Haroon.

3 Answers, 1 is accepted

Sort by
0
Boyko Markov
Telerik team
answered on 21 Jan 2008, 10:09 AM
Hi Haroon,

Thank you for writing.

  1. You are correct - if you remove all toolStripITems it's true that the toolStrip will dissapear. Furthermore, you cannot add/remove toolStripItems using its customize dialog. This is the case when the control is in AutoSize mode. When it is not in AutoSize mode, you will see it in spite of the fact that all its children are removed.
  2. The built-in functionality does not allow you to accomplish this.
  3. This is not the behavior by design. When you remove all buttonElements from a RadToolStripItem you should be able to add them again using its properties. However, they are not really removed but they are just collapsed.
  4. This cannot be accomplished with the current version of RadToolStrip. Please let me know whether this is of critical importance to you - I will do my best to implement this feature in the upcoming releases of RadControls for WinForms.

If you have any suggestions how to improve RadToolStrip and what features you would like to see, do not hesitate and write me back.

Sincerely yours,
Boyko Markov
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Meryl
Top achievements
Rank 1
answered on 04 Dec 2008, 06:40 PM
I'm hoping that I misunderstood your reply to the original post.  I am running your latest release for winforms.

I am looking for a toolstrip that the user can add or remove buttons or move the toolstrip elements.  Your toolstrip seemed to fit the bill.  Now, when the user removes some buttons, it is natural that you want this to be the saved state when the form is re-eopened, otherwise why bother to add or remove buttons???

How is this state saved?  Thanks very much!!

Meryl


0
Boyko Markov
Telerik team
answered on 05 Dec 2008, 03:51 PM
Hello Meryl,

We do not have this feature in our RadToolStrip. However I can provide you a simple code which can help you:

1. Inherit RadToolStrip and add the following code:
 
  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("RaToolStrip"); 
                ser.WriteObjectElement(writer, this); 
            } 
 
        } 
 
     
        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(); 
        } 




2. Save Layout in xml
 private void radButton1_Click(object sender, EventArgs e)
        {
            string s = "default.xml";
            SaveFileDialog dialog = new SaveFileDialog();
            dialog.Filter =
               "xml files (*.xml)|*.xml|All files (*.*)|*.*";
            dialog.Title = "Select a xml file";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                s = dialog.FileName;
            }

            this.radToolStrip1.SaveLayout(s);
        }

3. Load the layout from XML

        private void radButton2_Click(object sender, EventArgs e)
        {
            string s = "default.xml";
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter =
               "xml files (*.xml)|*.xml|All files (*.*)|*.*";
            dialog.Title = "Select a xml file";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                s = dialog.FileName;
            }

            this.radToolStrip1.LoadLayout(s);
        }

I hope this helps. I have tested it and it works pretty good but with some little small glitches.


Best wishes,
Boyko Markov
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Toolstrip (obsolete as of Q3 2010)
Asked by
Haroon
Top achievements
Rank 1
Answers by
Boyko Markov
Telerik team
Meryl
Top achievements
Rank 1
Share this question
or