/// <summary> /// 构造函数 /// </summary> /// <param name="titleNode">字体定义节点</param> public DUIFont(XmlNode fontNode) { if (fontNode != null) { //读取基础属性 _name = XMLConfigReader.ReadString("name", fontNode.Attributes["name"]); _backColor = XMLConfigReader.ReadColor(fontNode.Name, "backColor", fontNode.Attributes["backColor"]); _foreColor = XMLConfigReader.ReadColor(fontNode.Name, "foreColor", fontNode.Attributes["foreColor"]); string _fontFamily = XMLConfigReader.ReadString("fontFamily", fontNode.Attributes["fontFamily"]); int _fontSize = XMLConfigReader.ReadInt(fontNode.Name, "fontSize", fontNode.Attributes["fontSize"]); bool _fontBold = XMLConfigReader.ReadBoolean(fontNode.Name, "fontBold", fontNode.Attributes["fontBold"]); bool _fontItalic = XMLConfigReader.ReadBoolean(fontNode.Name, "fontItalic", fontNode.Attributes["fontItalic"]); bool _fontUnderline = XMLConfigReader.ReadBoolean(fontNode.Name, "fontUnderline", fontNode.Attributes["fontUnderline"]); bool _fontStrikeout = XMLConfigReader.ReadBoolean(fontNode.Name, "fontStrikeout", fontNode.Attributes["fontStrikeout"]); //构造组合属性 try { FontFamily fontFamily = new FontFamily(_fontFamily); FontStyle fontStyle = FontStyle.Regular; fontStyle = _fontBold ? (fontStyle | FontStyle.Bold) : fontStyle; fontStyle = _fontItalic ? (fontStyle | FontStyle.Italic) : fontStyle; fontStyle = _fontUnderline ? (fontStyle | FontStyle.Underline) : fontStyle; fontStyle = _fontStrikeout ? (fontStyle | FontStyle.Strikeout) : fontStyle; _font = new Font(fontFamily, _fontSize, fontStyle); } catch { _font = null; } } }
private string _fontName; //字体名 #endregion public LabelDUIStyle(XmlNode styleNode) : base(styleNode) { if (styleNode == null) { throw new Exception("传入了空的XmlNode对象,无法初始化LabelDUIStyle对象!"); } _fontName = XMLConfigReader.ReadString("fontName", styleNode.Attributes["fontName"]); }
private FlatStyle _flatStyle; //按钮点击外观样式 #endregion public ButtonDUIStyle(XmlNode styleNode) :base(styleNode) { if (styleNode == null) { throw new Exception("传入了空的XmlNode对象,无法初始化LabelDUIStyle对象!"); } //读取基础属性 _fontName = XMLConfigReader.ReadString("fontName", styleNode.Attributes["fontName"]); _flatStyle = XMLConfigReader.ReadFlatStyle(styleNode.Name, "flatStyle", styleNode.Attributes["flatStyle"]); }
/// <summary> /// 构造函数 /// </summary> /// <param name="titleNode">布局标题区定义节</param> public DUILayoutTitleInfo(XmlNode titleNode) { if (titleNode != null) { //读取基础属性 _iconSourceName = XMLConfigReader.ReadString("iconSourceName", titleNode.Attributes["iconSourceName"]); _showIcon = XMLConfigReader.ReadBoolean(titleNode.Name, "showIcon", titleNode.Attributes["showIcon"]); _text = XMLConfigReader.ReadString("text", titleNode.Attributes["text"]); _titleAreaHeight = XMLConfigReader.ReadInt(titleNode.Name, "titleAreaHeight", titleNode.Attributes["titleAreaHeight"]); _titleAreaOffset = XMLConfigReader.ReadInt(titleNode.Name, "titleAreaOffset", titleNode.Attributes["titleAreaOffset"]); _fontName = XMLConfigReader.ReadString("fontName", titleNode.Attributes["fontName"]); } }
/// <summary> /// 从XML配置文件加载按钮信息,形成分组和按钮对象 /// </summary> /// <param name="xmlDoc"></param> public void LoadButtonFromXml(XmlDocument xmlDoc) { if (xmlDoc == null) { throw new Exception("加载布局" + this._ownerLayout.Name + "中的背景按钮时,文档对象为空!"); } XmlElement layoutElement = xmlDoc.DocumentElement; foreach (XmlNode childNode in layoutElement.ChildNodes) { if (childNode.Name == "buttons") { foreach (XmlNode buttonNode in childNode.ChildNodes) { if (buttonNode.Name == "button") { if (buttonNode.Attributes["name"] != null && buttonNode.Attributes["position"] != null && buttonNode.Attributes["enable"] != null && buttonNode.Attributes["normalSourceName"] != null && buttonNode.Attributes["hoverSourceName"] != null && buttonNode.Attributes["downSourceName"] != null) { //enble属性为false,或者该属性不存在或非法值时,不加载该按钮 string enableString = buttonNode.Attributes["enable"].Value; if (string.IsNullOrEmpty(enableString) || (enableString.ToLower() != "true" && enableString.ToLower() != "false")) { continue; } bool enble = Convert.ToBoolean(enableString); if (enble == false) { continue; } //创建按钮对象 DUIButton newButton = new DUIButton(); newButton.Name = buttonNode.Attributes["name"].Value; newButton.Position = ConvertStringToPoint(newButton.Name, buttonNode.Attributes["position"].Value); newButton.NormalSourceName = buttonNode.Attributes["normalSourceName"].Value; newButton.HoverSourceName = buttonNode.Attributes["hoverSourceName"].Value; newButton.DownSourceName = buttonNode.Attributes["downSourceName"].Value; newButton.Status = ButtonStatus.Normal; newButton.HoldDown = false; newButton.Visible = true; //新加属性 newButton.Text = XMLConfigReader.ReadString("text", buttonNode.Attributes["text"]); newButton.TextAlignment = XMLConfigReader.ReadEnumTypeConfig <ContentAlignment>(buttonNode.Name, "textAlignment", buttonNode.Attributes["textAlignment"]); newButton.TextOffsetX = XMLConfigReader.ReadInt(buttonNode.Name, "textOffsetX", buttonNode.Attributes["textOffsetX"]); newButton.TextOffsetY = XMLConfigReader.ReadInt(buttonNode.Name, "textOffsetY", buttonNode.Attributes["textOffsetY"]); newButton.NormalFontName = XMLConfigReader.ReadString("normalFontName", buttonNode.Attributes["normalFontName"]); newButton.HoverFontName = XMLConfigReader.ReadString("hoverFontName", buttonNode.Attributes["hoverFontName"]); newButton.DownFontName = XMLConfigReader.ReadString("downFontName", buttonNode.Attributes["downFontName"]); string buttonGroupName = buttonNode.Attributes["group"] == null ? string.Empty : buttonNode.Attributes["group"].Value; if (buttonGroupName == string.Empty) { buttonGroupName = DUIButtonGroup.NormalGroupName; } if (!this._buttonGroupDict.ContainsKey(buttonGroupName)) { DUIButtonGroup newButtonGroup = new DUIButtonGroup(buttonGroupName, this); this._buttonGroupDict.Add(buttonGroupName, newButtonGroup); this._buttonGroupList.Add(newButtonGroup); } DUIButtonGroup buttonGroup = this._buttonGroupDict[buttonGroupName]; newButton.OwnerGroup = buttonGroup; buttonGroup.AddButton(newButton.Name, newButton); } } } } } }