Exemple #1
0
 private void btnSave_Click(object sender, System.EventArgs e)
 {
     if (LayoutList.Count > 0)
     {
         foreach (object obj in LayoutList)
         {
             Type   tp         = obj.GetType();
             string tpCategory = category + "\\" + tp.Name,
                    name       = "\\" + (ControlType as Type).Name + "[" + LayoutList.IndexOf(obj) + "].xml";
             if (!Directory.Exists(tpCategory))
             {
                 Directory.CreateDirectory(tpCategory);
             }
             if (tp.Equals(typeof(Search)))
             {
                 Search         srh     = obj as Search;
                 XmlDocument    xml     = new XmlDocument();
                 XmlDeclaration xd      = xml.CreateXmlDeclaration("1.0", "UTF-8", "yes");
                 XmlElement     xeRoot  = xml.CreateElement("Search");
                 XmlElement     xePopup = xml.CreateElement("Popup");
                 XmlAttribute   xaW     = xml.CreateAttribute("Width");
                 xaW.Value = srh.SearchWidth.ToString();
                 XmlAttribute xaH = xml.CreateAttribute("Height");
                 xaH.Value = srh.SearchHeight.ToString();
                 xePopup.Attributes.Append(xaW);
                 xePopup.Attributes.Append(xaH);
                 MemoryStream stream = new MemoryStream();
                 srh.gvSearch.SaveLayoutToStream(stream);
                 byte[] btData = new byte[stream.Length];
                 stream.Position = 0;
                 stream.Read(btData, 0, btData.Length);
                 XmlElement      xeGridView = xml.CreateElement("GridView");
                 XmlCDataSection xCdata     = xml.CreateCDataSection("");
                 xCdata.Data = Encoding.UTF8.GetString(btData);
                 xeGridView.AppendChild(xCdata);
                 xeRoot.AppendChild(xePopup);
                 xeRoot.AppendChild(xeGridView);
                 xml.AppendChild(xeRoot);
                 xml.Save(tpCategory + name);
             }
             else if (tp.Equals(typeof(GridControl)))
             {
                 (obj as GridControl).MainView.SaveLayoutToXml(tpCategory + name);
             }
             else if (tp.Equals(typeof(GridView)))
             {
                 (obj as GridView).SaveLayoutToXml(tpCategory + name);
             }
             else if (tp.Equals(typeof(LayoutControl)))
             {
                 (obj as LayoutControl).SaveLayoutToXml(tpCategory + name);
             }
             else if (tp.Equals(typeof(TreeList)))
             {
                 (obj as TreeList).SaveLayoutToXml(tpCategory + name);
             }
             else if (tp.Equals(typeof(SplitContainerControl)))
             {
                 XmlDocument    xml    = new XmlDocument();
                 XmlDeclaration xd     = xml.CreateXmlDeclaration("1.0", "UTF-8", "yes");
                 XmlElement     xeRoot = xml.CreateElement("SplitContainerControl");
                 XmlElement     xePos  = xml.CreateElement("Position");
                 XmlAttribute   xa     = xml.CreateAttribute("Value");
                 xa.Value = (obj as SplitContainerControl).SplitterPosition.ToString();
                 xePos.Attributes.Append(xa);
                 xeRoot.AppendChild(xePos);
                 xml.AppendChild(xeRoot);
                 xml.Save(tpCategory + name);
             }
         }
     }
     MessageBoxEx.Show("布局保存成功!", "提示", MessageBoxIcon.Information);
     this.DialogResult = DialogResult.OK;
 }