$99 VS $1000+. UI Control for ASP.NET AJAX(contains chart and gridview).
CommandBar Control for C# Windows Forms
Easily customize the flexible CommandBar Control in WinForms C# projects at design time
Home > WinForms UI Controls > User Manual > Save and Load Layout in C#

CommandBar Save and Load Layout for WinForms C# Tutorial

The WinForms CommandBar control is a powerful and easy to use user interface control for Windows Forms. This CommandBar control provides large flexibility for developers to customize it. By using the WinForms CommandBar control, developers can add and remove items, rearrange strip elements on different rows elements. The Save and Load layout functionality is able to help developers preserve user settings on location, visibility and orientation in their Windows Forms applications. With the Save layout feature, all the preferences of a user can be kept in an xml file. With the Load layout functionality, users can apply the layout settings to Command Bar.
The following C# Code shows a sample to implement a Save Layout button event handler by using the CommandBar control in Windows Forms template projects. Use the following C# code to initialize the layout.

private void button1_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.CommandBar1.CommandBarElement.SaveLayout(s);
}
The following C# code snippets illustrate the process of implementing a Load Layout button event handler in a Windows Forms template projects.

private void button2_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.CommandBar1.CommandBarElement.LoadLayout(s);
}
While using the Save and Load layout functionality, developers should pay attention on things that the Load layout will only load the settings for the items that the layout has been saved. The Load layout will not load and recreate the items that had been deleted.

How to Save and Load Scenario of CommandBar

The C# Code snippet below shows a sample to save the layout settings of a CommandBar after closing the parent form of the command bar as well as loading these settings when reopening this form. Normally, developers need to handle the Load and Form Closing events of the form.

private void SaveAndLoadLayout1_Load(object sender, EventArgs e)
{
if (File.Exists("Layout1.xml"))
{
this.commandBar1.CommandBarElement.LoadLayout("Layout1.xml");
}
}
UI Controlsfor Windows Forms
.NET WinForms UI Overview.NET WinForms UI Features.NET WinForms UI GuideC# WinForms UI DesignVB.NET WinForms UI Design
WinForms UI Controls