Convert INI format colors to standard System.Drawing.Color
Use Generic Color Configuration Support
This commit is contained in:
parent
1d0ea3e52b
commit
a73713e333
@ -13,6 +13,8 @@ using System.IO;
|
|||||||
using System.Xml;
|
using System.Xml;
|
||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using VEPROMS.CSLA.Library;
|
||||||
|
|
||||||
namespace Config
|
namespace Config
|
||||||
{
|
{
|
||||||
@ -45,9 +47,9 @@ namespace Config
|
|||||||
xParent.AppendChild(nd);
|
xParent.AppendChild(nd);
|
||||||
return nd;
|
return nd;
|
||||||
}
|
}
|
||||||
private void AddAttribute(XmlNode xParent, string sName, string sValue )
|
private void AddAttribute(XmlNode xParent, string sName, string sValue)
|
||||||
{
|
{
|
||||||
XmlNode xa=xParent.Attributes.GetNamedItem(sName);
|
XmlNode xa = xParent.Attributes.GetNamedItem(sName);
|
||||||
// bug fix. 09/15/03
|
// bug fix. 09/15/03
|
||||||
// If there was a space after an equal sign, that space character
|
// If there was a space after an equal sign, that space character
|
||||||
// was becomming part of the value string (reading the user.CFG file).
|
// was becomming part of the value string (reading the user.CFG file).
|
||||||
@ -56,27 +58,31 @@ namespace Config
|
|||||||
sValue = sValue.Trim(' ');
|
sValue = sValue.Trim(' ');
|
||||||
sName = sName.Replace(' ', '_');
|
sName = sName.Replace(' ', '_');
|
||||||
sName = sName.Replace("\\", "_slash_");
|
sName = sName.Replace("\\", "_slash_");
|
||||||
|
if (xParent.Name == "color")
|
||||||
// Add an attribute
|
|
||||||
if(sValue=="")
|
|
||||||
{
|
{
|
||||||
if(xa != null)
|
string[] parts = sValue.Split(",".ToCharArray());
|
||||||
|
sValue = ColorConfig.FindKnownColor(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2])).ToString();
|
||||||
|
}
|
||||||
|
// Add an attribute
|
||||||
|
if (sValue == "")
|
||||||
|
{
|
||||||
|
if (xa != null)
|
||||||
{
|
{
|
||||||
xParent.Attributes.RemoveNamedItem(sName);
|
xParent.Attributes.RemoveNamedItem(sName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(xa == null)
|
if (xa == null)
|
||||||
{
|
{
|
||||||
xa = xParent.OwnerDocument.CreateNode(System.Xml.XmlNodeType.Attribute ,sName,"");
|
xa = xParent.OwnerDocument.CreateNode(System.Xml.XmlNodeType.Attribute, sName, "");
|
||||||
xParent.Attributes.SetNamedItem(xa);
|
xParent.Attributes.SetNamedItem(xa);
|
||||||
}
|
}
|
||||||
xa.Value=sValue;
|
xa.Value = sValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
private XmlNode AddSection(XmlNode xParent, string sSection )
|
private XmlNode AddSection(XmlNode xParent, string sSection)
|
||||||
{
|
{
|
||||||
// get the name. If it's not in the 'migrated elements' list, then
|
// get the name. If it's not in the 'migrated elements' list, then
|
||||||
// preface the name with a 'z'.
|
// preface the name with a 'z'.
|
||||||
|
@ -84,24 +84,6 @@ namespace VEPROMS.CSLA.Library
|
|||||||
OnPropertyChanged("Printing_Length");
|
OnPropertyChanged("Printing_Length");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static Regex byARGB = new Regex(@"Color \[A=([0-9]*), R=([0-9]*), G=([0-9]*), B=([0-9]*)\]");
|
|
||||||
private static Regex byName = new Regex(@"Color \[(.*)\]");
|
|
||||||
public static Color ColorFromString(string sColor)
|
|
||||||
{
|
|
||||||
Match myMatch = byARGB.Match(sColor);
|
|
||||||
if (myMatch.Groups.Count == 5)
|
|
||||||
return Color.FromArgb(int.Parse(myMatch.Groups[1].Value), int.Parse(myMatch.Groups[2].Value), int.Parse(myMatch.Groups[3].Value), int.Parse(myMatch.Groups[4].Value));
|
|
||||||
myMatch = byName.Match(sColor);
|
|
||||||
if (myMatch.Groups.Count == 2)
|
|
||||||
return Color.FromName(myMatch.Groups[1].Value);
|
|
||||||
if (sColor[0] == '[')
|
|
||||||
{
|
|
||||||
string[] parts = sColor.Substring(1, sColor.Length - 2).Split(",".ToCharArray());
|
|
||||||
return Color.FromArgb(Int32.Parse(parts[0]), Int32.Parse(parts[1]), Int32.Parse(parts[2]), Int32.Parse(parts[3]));
|
|
||||||
}
|
|
||||||
else return Color.FromName(sColor);
|
|
||||||
|
|
||||||
}
|
|
||||||
[Category("Printing")]
|
[Category("Printing")]
|
||||||
[DisplayName("Color")]
|
[DisplayName("Color")]
|
||||||
[Description("Color of Document Text")]
|
[Description("Color of Document Text")]
|
||||||
@ -110,7 +92,7 @@ namespace VEPROMS.CSLA.Library
|
|||||||
get
|
get
|
||||||
{
|
{
|
||||||
string sColor = _Xp["Printing", "Color"];
|
string sColor = _Xp["Printing", "Color"];
|
||||||
return ColorFromString(sColor);
|
return ColorConfig.ColorFromString(sColor);
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
|
@ -1051,21 +1051,11 @@ namespace VEPROMS.CSLA.Library
|
|||||||
get
|
get
|
||||||
{
|
{
|
||||||
string sColor = _Xp["default", "BkColor"];
|
string sColor = _Xp["default", "BkColor"];
|
||||||
if (sColor == string.Empty) sColor = "White";
|
return ColorConfig.ColorFromString(sColor);
|
||||||
if (sColor[0] == '[')
|
|
||||||
{
|
|
||||||
string[] parts = sColor.Substring(1, sColor.Length - 2).Split(",".ToCharArray());
|
|
||||||
return Color.FromArgb(Int32.Parse(parts[0]), Int32.Parse(parts[1]), Int32.Parse(parts[2]));
|
|
||||||
}
|
|
||||||
else return Color.FromName(sColor);
|
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value.IsNamedColor) _Xp["default", "BkColor"] = value.Name;
|
_Xp["default", "BkColor"] = value.ToString();
|
||||||
else
|
|
||||||
{
|
|
||||||
_Xp["default", "BkColor"] = string.Format("[{0},{1},{2}]", value.R, value.G, value.B);
|
|
||||||
}
|
|
||||||
OnPropertyChanged("Default_BkColor");
|
OnPropertyChanged("Default_BkColor");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user