// // /// <summary> // /// 将一个字符串转换为整数 // /// </summary> // /// <param name="strData">字符串</param> // /// <param name="DefaultValue">默认值</param> // /// <returns>转换结果</returns> // private static int ToInt32Value(string strData , int DefaultValue) // { // try // { // if(strData == null) // return DefaultValue; // else // return Convert.ToInt32(strData); // } // catch // { // return DefaultValue; // } // } // // // /// <summary> // /// 将 #xxxxxx 字符串转换为一个颜色值 // /// </summary> // /// <param name="strText">#xxxxxx 格式的字符串</param> // /// <param name="DefaultValue">若转换失败则使用的默认值</param> // /// <returns>转换结果</returns> // private static System.Drawing.Color ColorFromHtml(string strText, System.Drawing.Color DefaultValue ) // { // if(strText != null) // { // strText = strText.ToUpper().Trim(); // if(strText.StartsWith("#") && strText.Length <= 7 ) // { // int iValue = 0 ; // int Index = 0; // const string c_HexList = "0123456789ABCDEF"; // for(int iCount = 1 ; iCount < strText.Length ; iCount ++ ) // { // Index = c_HexList.IndexOf(strText[iCount]); // if( Index >= 0 ) // iValue = iValue * 16 + Index ; // else // return DefaultValue ; // } // System.Drawing.Color myColor = System.Drawing.Color.FromArgb(iValue); // return System.Drawing.Color.FromArgb(255,myColor); // } // } // return DefaultValue; // } // // /// <summary> // /// 将一个颜色值转换为 #XXXXXX 格式的字符串 // /// </summary> // /// <param name="intValue">整数值</param> // /// <returns>转换后的字符串</returns> // private static string ColorToHtml(System.Drawing.Color myColor) // { // return "#" + Convert.ToInt32(myColor.ToArgb() & 0xffffff).ToString("X6"); // } #endregion /// <summary> /// 设置所有参数为默认值 /// </summary> public void Clear() { leftWidth = DefaultWidth; leftStyle = DefaultStyle; topColor = DefaultColor; topWidth = DefaultWidth; topStyle = DefaultStyle; rightColor = DefaultColor; rightWidth = DefaultWidth; rightStyle = DefaultStyle; bottomColor = DefaultColor; bottomWidth = DefaultWidth; bottomStyle = DefaultStyle; hasBackGround = false; backColor = DefaultBackColor; }
/// <summary> /// 从其他的边框样式对象拷贝数据 /// </summary> /// <param name="b">数据来源的边框样式对象</param> public void CopyFrom(ZYTextBorder b) { if (b != null) { leftColor = b.leftColor; leftStyle = b.leftStyle; leftWidth = b.leftWidth; topColor = b.topColor; topStyle = b.topStyle; topWidth = b.topWidth; rightColor = b.rightColor; rightStyle = b.rightStyle; rightWidth = b.rightWidth; bottomColor = b.bottomColor; bottomStyle = b.bottomStyle; bottomWidth = b.bottomWidth; } }
/// <summary> /// 向XML节点加载对象数据,该函数不会重置所有的数据 /// </summary> /// <param name="myElement">XML节点对象</param> /// <returns>加载是否成功</returns> public bool FromXMLWithoutClear(System.Xml.XmlElement myElement) { if (myElement != null) { // all if (myElement.HasAttribute(c_Border_Color)) { this.BorderColor = StringCommon.ColorFromHtml(myElement.GetAttribute(c_Border_Color), DefaultColor); } if (myElement.HasAttribute(c_Border_Width)) { this.BorderWidth = StringCommon.ToInt32Value(myElement.GetAttribute(c_Border_Width), DefaultWidth); } if (myElement.HasAttribute(c_Border_Style)) { this.BorderStyle = ToBorderStyle(myElement.GetAttribute(c_Border_Style)); } // left if (myElement.HasAttribute(c_Border_Left_Color)) { leftColor = StringCommon.ColorFromHtml(myElement.GetAttribute(c_Border_Left_Color), DefaultColor); } if (myElement.HasAttribute(c_Border_Left_Width)) { leftWidth = StringCommon.ToInt32Value(myElement.GetAttribute(c_Border_Left_Width), DefaultWidth); } if (myElement.HasAttribute(c_Border_Left_Style)) { leftStyle = ToBorderStyle(myElement.GetAttribute(c_Border_Left_Style)); } // top if (myElement.HasAttribute(c_Border_Top_Color)) { topColor = StringCommon.ColorFromHtml(myElement.GetAttribute(c_Border_Top_Color), DefaultColor); } if (myElement.HasAttribute(c_Border_Top_Width)) { topWidth = StringCommon.ToInt32Value(myElement.GetAttribute(c_Border_Top_Width), DefaultWidth); } if (myElement.HasAttribute(c_Border_Top_Style)) { topStyle = ToBorderStyle(myElement.GetAttribute(c_Border_Top_Style)); } // right if (myElement.HasAttribute(c_Border_Right_Color)) { rightColor = StringCommon.ColorFromHtml(myElement.GetAttribute(c_Border_Right_Color), DefaultColor); } if (myElement.HasAttribute(c_Border_Right_Width)) { rightWidth = StringCommon.ToInt32Value(myElement.GetAttribute(c_Border_Right_Width), DefaultWidth); } if (myElement.HasAttribute(c_Border_Right_Style)) { rightStyle = ToBorderStyle(myElement.GetAttribute(c_Border_Right_Style)); } // bottom if (myElement.HasAttribute(c_Border_Bottom_Color)) { bottomColor = StringCommon.ColorFromHtml(myElement.GetAttribute(c_Border_Bottom_Color), DefaultColor); } if (myElement.HasAttribute(c_Border_Bottom_Width)) { bottomWidth = StringCommon.ToInt32Value(myElement.GetAttribute(c_Border_Bottom_Width), DefaultWidth); } if (myElement.HasAttribute(c_Border_Bottom_Style)) { bottomStyle = ToBorderStyle(myElement.GetAttribute(c_Border_Bottom_Style)); } // 背景色 hasBackGround = myElement.HasAttribute(c_BackGround_Color); if (hasBackGround) { backColor = StringCommon.ColorFromHtml(myElement.GetAttribute(c_BackGround_Color), DefaultBackColor); } else { backColor = DefaultBackColor; } return(true); } return(false); }