public
partial
class
RadForm1 : Telerik.WinControls.UI.RadForm
{
public
RadForm1()
{
InitializeComponent();
}
string
layout = @
"..\..\layout.xml"
;
private
void
radButton1_Click(
object
sender, EventArgs e)
{
XmlDocument doc =
this
.SaveLayoutCore();
doc.Save(layout);
}
private
XmlDocument SaveLayoutCore()
{
XmlDocument doc =
new
XmlDocument();
XmlDeclaration dec = doc.CreateXmlDeclaration(
"1.0"
,
null
,
null
);
doc.AppendChild(dec);
XmlElement rootNode = doc.CreateElement(
"RadCommandBarElement"
);
rootNode.SetAttribute(
"Orientation"
,
this
.radCommandBar1.CommandBarElement.Orientation.ToString());
rootNode.SetAttribute(
"Name"
,
this
.Name);
rootNode.SetAttribute(
"RTL"
,
this
.RightToLeft.ToString());
for
(
int
i = 0; i <
this
.radCommandBar1.CommandBarElement.Rows.Count; i++)
{
CommandBarRowElement lineElement =
this
.radCommandBar1.CommandBarElement.Rows[i];
XmlElement lineNode = doc.CreateElement(
"CommandBarRowElement"
);
lineNode.SetAttribute(
"Orientation"
, lineElement.Orientation.ToString());
lineNode.SetAttribute(
"Name"
, lineElement.Name);
lineNode.SetAttribute(
"LineIndex"
, i.ToString());
foreach
(CommandBarStripElement stripElement
in
lineElement.Strips)
{
XmlElement stripNode = doc.CreateElement(
"CommandBarStripElement"
);
stripNode.SetAttribute(
"Orientation"
, stripElement.Orientation.ToString());
stripNode.SetAttribute(
"Name"
, stripElement.Name);
stripNode.SetAttribute(
"DesiredLocationX"
,
this
.DescaleFloat(stripElement.DesiredLocation.X).ToString());
stripNode.SetAttribute(
"DesiredLocationY"
,
this
.DescaleFloat(stripElement.DesiredLocation.Y).ToString());
stripNode.SetAttribute(
"VisibleInCommandBar"
, stripElement.VisibleInCommandBar.ToString());
stripNode.SetAttribute(
"StretchHorizontally"
, stripElement.StretchHorizontally.ToString());
stripNode.SetAttribute(
"StretchVertically"
, stripElement.StretchVertically.ToString());
stripNode.SetAttribute(
"EnableFloating"
, stripElement.EnableFloating.ToString());
stripNode.SetAttribute(
"EnableDragging"
, stripElement.EnableDragging.ToString());
int
currentIndex = 0;
for
(
int
j = 0; j < stripElement.Items.Count; j++)
{
RadCommandBarBaseItem itemElement = stripElement.Items[j];
XmlElement itemNode = doc.CreateElement(
"RadCommandBarBaseItem"
);
itemNode.SetAttribute(
"Orientation"
, itemElement.Orientation.ToString());
itemNode.SetAttribute(
"Name"
, itemElement.Name);
itemNode.SetAttribute(
"VisibleInStrip"
, itemElement.VisibleInStrip.ToString());
itemNode.SetAttribute(
"StretchHorizontally"
, itemElement.StretchHorizontally.ToString());
itemNode.SetAttribute(
"StretchVertically"
, itemElement.StretchVertically.ToString());
itemNode.SetAttribute(
"Index"
, currentIndex.ToString());
stripNode.AppendChild(itemNode);
++currentIndex;
}
for
(
int
j = 0; j < stripElement.OverflowButton.OverflowPanel.Layout.Children.Count; j++)
{
RadCommandBarBaseItem itemElement = stripElement.OverflowButton.OverflowPanel.Layout.Children[j]
as
RadCommandBarBaseItem;
if
(itemElement ==
null
)
{
continue
;
}
XmlElement itemNode = doc.CreateElement(
"RadCommandBarBaseItem"
);
itemNode.SetAttribute(
"Orientation"
, itemElement.Orientation.ToString());
itemNode.SetAttribute(
"Name"
, itemElement.Name);
itemNode.SetAttribute(
"VisibleInStrip"
, itemElement.VisibleInStrip.ToString());
itemNode.SetAttribute(
"StretchHorizontally"
, itemElement.StretchHorizontally.ToString());
itemNode.SetAttribute(
"StretchVertically"
, itemElement.StretchVertically.ToString());
itemNode.SetAttribute(
"Index"
, currentIndex.ToString());
stripNode.AppendChild(itemNode);
++currentIndex;
}
lineNode.AppendChild(stripNode);
}
rootNode.AppendChild(lineNode);
}
XmlElement floatingFormsNode = SaveFloatingStripsLayout(doc);
rootNode.AppendChild(floatingFormsNode);
doc.AppendChild(rootNode);
return
doc;
}
private
XmlElement SaveFloatingStripsLayout(XmlDocument doc)
{
XmlElement floatingFormsNode = doc.CreateElement(
"FloatingStrips"
);
foreach
(CommandBarStripElement stripElement
in
this
.radCommandBar1.CommandBarElement.StripInfoHolder.StripInfoList)
{
if
(stripElement.FloatingForm ==
null
|| stripElement.FloatingForm.IsDisposed)
{
continue
;
}
XmlElement stripNode = doc.CreateElement(
"CommandBarStripElement"
);
stripNode.SetAttribute(
"Orientation"
, stripElement.Orientation.ToString());
stripNode.SetAttribute(
"Name"
, stripElement.Name);
stripNode.SetAttribute(
"DesiredLocationX"
,
this
.DescaleFloat(stripElement.DesiredLocation.X).ToString());
stripNode.SetAttribute(
"DesiredLocationY"
,
this
.DescaleFloat(stripElement.DesiredLocation.Y).ToString());
stripNode.SetAttribute(
"FormLocationX"
, stripElement.FloatingForm.Location.X.ToString());
stripNode.SetAttribute(
"FormLocationY"
, stripElement.FloatingForm.Location.Y.ToString());
stripNode.SetAttribute(
"VisibleInCommandBar"
, stripElement.VisibleInCommandBar.ToString());
stripNode.SetAttribute(
"StretchHorizontally"
, stripElement.StretchHorizontally.ToString());
stripNode.SetAttribute(
"StretchVertically"
, stripElement.StretchVertically.ToString());
stripNode.SetAttribute(
"RTL"
, stripElement.RightToLeft.ToString());
stripNode.SetAttribute(
"EnableFloating"
, stripElement.EnableFloating.ToString());
stripNode.SetAttribute(
"EnableDragging"
, stripElement.EnableDragging.ToString());
int
currentIndex = 0;
for
(
int
j = 0; j < stripElement.Items.Count; j++)
{
RadCommandBarBaseItem itemElement = stripElement.Items[j];
XmlElement itemNode = doc.CreateElement(
"RadCommandBarBaseItem"
);
itemNode.SetAttribute(
"Orientation"
, itemElement.Orientation.ToString());
itemNode.SetAttribute(
"Name"
, itemElement.Name);
itemNode.SetAttribute(
"VisibleInStrip"
, itemElement.VisibleInStrip.ToString());
itemNode.SetAttribute(
"StretchHorizontally"
, itemElement.StretchHorizontally.ToString());
itemNode.SetAttribute(
"StretchVertically"
, itemElement.StretchVertically.ToString());
itemNode.SetAttribute(
"Index"
, currentIndex.ToString());
stripNode.AppendChild(itemNode);
++currentIndex;
}
for
(
int
j = 0; j < stripElement.FloatingForm.ItemsHostControl.Element.Layout.Children.Count; j++)
{
RadCommandBarBaseItem itemElement = stripElement.FloatingForm.ItemsHostControl.Element.Layout.Children[j]
as
RadCommandBarBaseItem;
if
(itemElement ==
null
)
{
continue
;
}
XmlElement itemNode = doc.CreateElement(
"RadCommandBarBaseItem"
);
itemNode.SetAttribute(
"Orientation"
, itemElement.Orientation.ToString());
itemNode.SetAttribute(
"Name"
, itemElement.Name);
itemNode.SetAttribute(
"VisibleInStrip"
, itemElement.VisibleInStrip.ToString());
itemNode.SetAttribute(
"StretchHorizontally"
, itemElement.StretchHorizontally.ToString());
itemNode.SetAttribute(
"StretchVertically"
, itemElement.StretchVertically.ToString());
itemNode.SetAttribute(
"Index"
, currentIndex.ToString());
stripNode.AppendChild(itemNode);
++currentIndex;
}
floatingFormsNode.AppendChild(stripNode);
}
return
floatingFormsNode;
}
private
float
DescaleFloat(
float
value)
{
SizeF descale =
new
SizeF(1 /
this
.radCommandBar1.RootElement.DpiScaleFactor.Width, 1 /
this
.radCommandBar1.RootElement.DpiScaleFactor.Height);
return
TelerikDpiHelper.ScaleFloat(value, descale);
}
private
void
radButton2_Click(
object
sender, EventArgs e)
{
this
.radCommandBar1.CommandBarElement.LoadLayout(layout);
}
}