public void LoadFromXmlElement(XmlElement root) { OnResolutionChanged(); var val = root.GetAttribute("Name"); if (!String.IsNullOrEmpty(val)) { Name = val; } val = root.GetAttribute("IsVisible"); if (!String.IsNullOrEmpty(val)) { IsVisible = bool.Parse(val); } TimeLength = Convert.ToSingle(root.GetAttribute("TimeLength")); val = root.GetAttribute("SwitchMode"); if (!String.IsNullOrEmpty(val)) { SwitchMode = (ViewportSwitchMode)Enum.Parse(typeof(ViewportSwitchMode), val); } else { SwitchMode = ViewportSwitchMode.时间切换; } val = root.GetAttribute("SwitchHotKey"); if (!String.IsNullOrEmpty(val)) { SwitchHotKey = (System.Windows.Forms.Keys)Enum.Parse(typeof(System.Windows.Forms.Keys), val); } else { SwitchHotKey = System.Windows.Forms.Keys.None; } val = root.GetAttribute("ElementsCaptionColor"); int dwClr; if (!String.IsNullOrEmpty(val) && Int32.TryParse(val, out dwClr)) { ElementsCaptionColor = System.Drawing.Color.FromArgb(dwClr); } val = root.GetAttribute("ElementsCaptionScale"); if (!String.IsNullOrEmpty(val)) { ElementsCaptionScale = float.Parse(val); } foreach (XmlElement node in root.GetElementsByTagName("Element")) { if (node.ParentNode == root) { var kind = (ResourceKind)Enum.Parse(typeof(ResourceKind), node.GetAttribute("Kind")); var file = node.GetAttribute("ResourceFile"); var res = ProjectDoc.Instance.ResourceGroups[kind].GetResourceInfo(file); if (res != null) { var e = ElementInfo.CreateElement(res, this, new System.Drawing.PointF(0, 0)); AddElement(e); e.LoadFromXmlElement(node); } } } ElemGroupCollector.LoadFromParentXmlElement(root); }
public XmlElement GenerateXmlElement(XmlDocument doc) { var node = doc.CreateElement("Viewport"); node.SetAttribute("Index", ScreenIndex.ToString()); node.SetAttribute("Name", Name); if (!IsVisible) { node.SetAttribute("IsVisible", IsVisible.ToString()); } node.SetAttribute("TimeLength", TimeLength.ToString()); node.SetAttribute("SwitchMode", SwitchMode.ToString()); node.SetAttribute("SwitchHotKey", SwitchHotKey.ToString()); if (ElementsCaptionColor != System.Drawing.Color.White) { node.SetAttribute("ElementsCaptionColor", ElementsCaptionColor.ToArgb().ToString()); } if (ElementsCaptionScale != 1) { node.SetAttribute("ElementsCaptionScale", ElementsCaptionScale.ToString()); } foreach (var elm in Elements) { if (elm == null) { continue; } if (elm.Resource != null && elm.Resource.FullFilePath == ResourceInfo_BackgroundImage.DefaultBackgroundImageFile) { continue; } var enode = elm.GenerateXmlElement(doc); node.AppendChild(enode); } var gnode = ElemGroupCollector.GenerateXmlElement(doc); if (gnode != null) { node.AppendChild(gnode); } return(node); }