本文整理汇总了C#中System.Drawing.ColorConverter.ConvertFromString方法的典型用法代码示例。如果您正苦于以下问题:C# ColorConverter.ConvertFromString方法的具体用法?C# ColorConverter.ConvertFromString怎么用?C# ColorConverter.ConvertFromString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.ColorConverter
的用法示例。
在下文中一共展示了ColorConverter.ConvertFromString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FromString
private GradientFill FromString(object value)
{
string[] values = ((string)value).Split(',');
if (values.Length != 3)
throw new ArgumentException("Could not convert the value");
try
{
GradientFill gradient = new GradientFill();
ColorConverter converter = new ColorConverter();
gradient.ColorA = (Color)converter.ConvertFromString(values[0]);
gradient.ColorB = (Color)converter.ConvertFromString(values[1]);
// Convert the name of the enumerated value into the corresponding
// enumerated value (which is actually an integer constant).
gradient.GradientFillStyle = (LinearGradientMode)Enum.Parse(
typeof(LinearGradientMode), values[2], true);
return gradient;
}
catch
{
throw new ArgumentException("Could not convert the value");
}
}
示例2: FromString
private GradientTab FromString(object value)
{
var result = ((string)value).Split(',');
if (result.Length != 6)
throw new ArgumentException("Could not convert to value");
try
{
var gradient = new GradientTab();
// Retrieve the colors
var converter = new ColorConverter();
gradient.ColorStart = (Color)converter.ConvertFromString(result[0]);
gradient.ColorEnd = (Color)converter.ConvertFromString(result[1]);
gradient.GradientStyle = (LinearGradientMode)Enum.Parse(typeof(LinearGradientMode), result[2], true);
gradient.TabPageTextColor = (Color)converter.ConvertFromString(result[3]);
gradient.TabPageSelectedTextColor = (Color)converter.ConvertFromString(result[4]);
gradient.SelectedTabFontStyle = (FontStyle)Enum.Parse(typeof(FontStyle), result[5], true);
return gradient;
}
catch (Exception)
{
throw new ArgumentException("Could not convert to value");
}
}
示例3: FromString
private ButtonsCaption FromString(object value)
{
var result = ((string)value).Split(',');
if (result.Length != 2)
throw new ArgumentException("Could not convert to value");
try
{
var buttons = new ButtonsCaption();
// Retrieve the colors
var converter = new ColorConverter();
var resultColor0 = converter.ConvertFromString(result[0]);
if (resultColor0 != null)
buttons.ActiveCaptionButtonsColor = (Color)resultColor0;
var resultColor1 = converter.ConvertFromString(result[1]);
if (resultColor1 != null)
buttons.InactiveCaptionButtonsColor = (Color)resultColor1;
return buttons;
}
catch (Exception)
{
throw new ArgumentException("Could not convert to value");
}
}
示例4: deserializeFromXml
public override void deserializeFromXml( XmlNode element )
{
if (element.ChildNodes.Count < 1)
return;
XmlElement e = element.ChildNodes[0] as XmlElement;
if (e == null)
{
return;
}
_text = e.InnerText;
FontConverter fontConverter = new FontConverter();
ColorConverter colorConverter = new ColorConverter();
if (e.HasAttribute("Color")) {
//_color = (Color)colorConverter.ConvertFromString(e.Attributes["Color"].Value);
_color = (Color)colorConverter.ConvertFromString(null, System.Globalization.CultureInfo.InvariantCulture, e.Attributes["Color"].Value);
}
if (e.HasAttribute("Background") ) {
_background = (Color)colorConverter.ConvertFromString(null,System.Globalization.CultureInfo.InvariantCulture, e.Attributes["Background"].Value);
}
if (e.HasAttribute("Font")) {
_font = fontConverter.ConvertFromString(null, System.Globalization.CultureInfo.InvariantCulture, e.Attributes["Font"].Value ) as Font;
} else {
_font = SystemFonts.DefaultFont;
}
if ( e.HasAttribute("Alignment"))
_alignment = StringToAlignment(e.Attributes["Alignment"].Value);
}
示例5: ThresholdDataSet
public ThresholdDataSet(IController controller, Int32 configurationID)
{
organizationData = new ThresholdData("Organization");
roleData = new ThresholdData("Role");
billetData = new ThresholdData("Billet");
informationProductData = new ThresholdData("Information Product");
activityData = new ThresholdData("Activity");
thresholdData = new ThresholdData[] { organizationData, roleData, billetData, informationProductData, activityData };
XPathNodeIterator thresholds = controller.GetComponentAndChildren(configurationID, "Configuration", new ComponentOptions()).CreateNavigator().Select("/Components/Component/Component[@Type='Threshold']");
if (thresholds.Count != 0)
{
ColorConverter cv = new ColorConverter();
String baseString = "ComponentParameters/Parameter[@category='Threshold']/Parameter[@displayedName='";
foreach (XPathNavigator threshold in thresholds)
{
String name = threshold.GetAttribute("Name", "");
Double _lv = Double.Parse(threshold.SelectSingleNode(baseString + "LowerThresholdValue']/@value").ToString());
Double _mv1 = Double.Parse(threshold.SelectSingleNode(baseString + "MiddleThresholdValue1']/@value").ToString());
Double _mv2 = Double.Parse(threshold.SelectSingleNode(baseString + "MiddleThresholdValue2']/@value").ToString());
Double _uv = Double.Parse(threshold.SelectSingleNode(baseString + "UpperThresholdValue']/@value").ToString());
Boolean _lowerCheck = Boolean.Parse(threshold.SelectSingleNode(baseString + "LowerThresholdValueIsEqual']/@value").ToString());
Boolean _middleCheck1 = Boolean.Parse(threshold.SelectSingleNode(baseString + "MiddleThresholdValue1IsEqual']/@value").ToString());
Boolean _middleCheck2 = Boolean.Parse(threshold.SelectSingleNode(baseString + "MiddleThresholdValue2IsEqual']/@value").ToString());
Boolean _upperCheck = Boolean.Parse(threshold.SelectSingleNode(baseString + "UpperThresholdValueIsEqual']/@value").ToString());
Color _lowerColor = (Color)cv.ConvertFromString(threshold.SelectSingleNode(baseString + "LowerThresholdColor']/@value").ToString());
Color _middleColor = (Color)cv.ConvertFromString(threshold.SelectSingleNode(baseString + "MiddleThresholdColor']/@value").ToString());
Color _upperColor = (Color)cv.ConvertFromString(threshold.SelectSingleNode(baseString + "UpperThresholdColor']/@value").ToString());
bool found = false;
for(int i = 0; i < thresholdData.Length; i++)
{
ThresholdData data = thresholdData[i];
if (data.Name.Equals(name))
{
found = true;
data.LowerValue = _lv;
data.MiddleValue1 = _mv1;
data.MiddleValue2 = _mv2;
data.UpperValue = _uv;
data.LowerCheck = _lowerCheck;
data.MiddleCheck1 = _middleCheck1;
data.MiddleCheck2 = _middleCheck2;
data.UpperCheck = _upperCheck;
data.LowerColor = _lowerColor;
data.MiddleColor = _middleColor;
data.UpperColor = _upperColor;
}
}
if (!found)
{
throw new Exception("Could not find threshold data: " + name);
}
}
}
}
示例6: Matcher
public Matcher(string mS)
{
var array = mS.Split(new[] { ";;" }, StringSplitOptions.None);
Enabled = bool.Parse(array[0]);
Name = array[1];
var cc = new ColorConverter();
BackColor = (Color)cc.ConvertFromString(array[2]);
ForeColor = (Color)cc.ConvertFromString(array[3]);
Expression = array[4];
}
示例7: GetShapeFromPoints
public static List<Shape> GetShapeFromPoints(List<List<int>> points, string hexcolor, int width, int height, string outName)
{
List<Pixel> square = new List<Pixel>();
ColorConverter cc = new ColorConverter();
Color color = (Color) cc.ConvertFromString(hexcolor);
Point p0 = new Point(points.ElementAt(0).ElementAt(0), points.ElementAt(0).ElementAt(1));
Point p1 = new Point(points.ElementAt(1).ElementAt(0), points.ElementAt(1).ElementAt(1));
Point p2 = new Point(points.ElementAt(2).ElementAt(0), points.ElementAt(2).ElementAt(1));
Point p3 = new Point(points.ElementAt(3).ElementAt(0), points.ElementAt(3).ElementAt(1));
Pixel[] corners = new Pixel[4];
corners[0] = new Pixel(color, p0.X, p0.Y);
corners[1] = new Pixel(color, p1.X, p1.Y);
corners[2] = new Pixel(color, p2.X, p2.Y);
corners[3] = new Pixel(color, p3.X, p3.Y);
for (int x=0; x< width; x+=1)
{
for(int y=0;y< height;y+=1)
{
if (PointChecker.PointInQuad(new Point(x, y), p0, p1, p2, p3))
{
square.Add(new Pixel(color, x, y));
}
}
}
Shape shape = new Shape(square, corners);
return new List<Shape>() { shape };
}
示例8: OutPut
private static void OutPut(string text = null, string foregroundColor = null, string backgroundColor = null)
{
Func<string, Color> getColor = (s) =>
{
var colorConverter = new ColorConverter();
return (Color)colorConverter.ConvertFromString(s);
};
Predicate<string> notNullofEmpty = x => !string.IsNullOrEmpty(x);
if (notNullofEmpty(backgroundColor))
{
ColorSetter.BackgroundColor = getColor(backgroundColor);
}
if (notNullofEmpty(foregroundColor))
{
ColorSetter.ForegroundColor = getColor(foregroundColor);
}
if (notNullofEmpty(text))
{
Console.Write(text);
}
ColorSetter.BackgroundColor = getColor(GameConfig.ColorStrings[0]);
}
示例9: ReadXml
public void ReadXml(System.Xml.XmlReader reader)
{
if (reader.IsEmptyElement) { return; }
ColorConverter cconv = new ColorConverter();
if (reader.NodeType != System.Xml.XmlNodeType.EndElement) {
this._color = (Color)cconv.ConvertFromString(reader.ReadString());
}
reader.MoveToContent();
reader.ReadEndElement();
}
示例10: CreateImage
/// <summary>
/// 获取验证码图片
/// </summary>
/// <param name="checkCode">验证码</param>
/// <returns></returns>
public System.IO.MemoryStream CreateImage(string checkCode)
{
int iwidth = (int)(checkCode.Length * 12);
ColorConverter colConvert = new ColorConverter();
System.Drawing.Bitmap image = new System.Drawing.Bitmap(iwidth, 20);
Graphics g = Graphics.FromImage(image);
Font f = new System.Drawing.Font("Arial", 10, System.Drawing.FontStyle.Bold);
Brush b = new System.Drawing.SolidBrush((Color)colConvert.ConvertFromString("#FFFFFF"));
Color color = (System.Drawing.Color)colConvert.ConvertFromString("#315CA1");
g.Clear(color);
g.DrawString(checkCode, f, b, 3, 3);
Pen blackPen = new Pen(Color.Red, 0);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
g.Dispose();
image.Dispose();
return ms;
}
示例11: GetColorFromString
/// <summary>
/// 字符串转颜色
/// </summary>
/// <param name="colorString"></param>
/// <returns></returns>
public static Color GetColorFromString(string colorString)
{
Color color = Color.Empty;
ColorConverter converter = new ColorConverter();
//try
//{
color = (Color)converter.ConvertFromString(colorString);
//}
//catch
//{ }
return color;
}
示例12: ConvertToColor
private Color ConvertToColor(string colorString)
{
try
{
var colorConverter = new ColorConverter();
return (Color) colorConverter.ConvertFromString(colorString);
}
catch (Exception)
{
throw new InvalidCastException("String provided is not in a recognized Hex format.");
}
}
示例13: FromString
private CaptionGradient FromString(object value)
{
string[] result = ((string)value).Split(',');
if (result.Length != 8)
throw new ArgumentException("Could not convert to value");
try
{
CaptionGradient gradient = new CaptionGradient();
// Retrieve the colors
ColorConverter converter = new ColorConverter();
gradient.ActiveCaptionColorStart = (Color)converter.ConvertFromString(result[0]);
gradient.ActiveCaptionColorEnd = (Color)converter.ConvertFromString(result[1]);
gradient.InactiveCaptionColorStart = (Color)converter.ConvertFromString(result[2]);
gradient.InactiveCaptionColorEnd = (Color)converter.ConvertFromString(result[3]);
gradient.CaptionGradientStyle = (LinearGradientMode)Enum.Parse(typeof(LinearGradientMode), result[4], true);
gradient.InactiveCaptionTextColor = (Color)converter.ConvertFromString(result[5]);
gradient.ActiveCaptionTextColor = (Color)converter.ConvertFromString(result[6]);
gradient.ActiveCaptionFontStyle = (FontStyle)Enum.Parse(typeof(FontStyle), result[7], true);
return gradient;
}
catch (Exception)
{
throw new ArgumentException("Could not convert to value");
}
}
示例14: GetCorrectColor
public static Color GetCorrectColor(string input)
{
ColorConverter converter = new ColorConverter();
object fromString = converter.ConvertFromString(input);
if (fromString == null) return Color.Black;
Color converted = (Color) fromString;
if (converted.A == 0)
{
converted = Color.FromArgb(255, converted);
}
return Color.FromArgb(converted.A, converted.B, converted.G, converted.R);
}
示例15: ColorListView
public void ColorListView()
{
ColorConverter c = new ColorConverter();
//lstVw_ActorsList.BackColor = Color.Ivory;
//lstVw_ActorsList.BackColor = Color.Lavender;
lstVw_ActorsList.ForeColor = (Color)c.ConvertFromString("#333333");
for (int i = 0; i < lstVw_ActorsList.Items.Count; i++)
{
//if (i % 2 == 0)
//{
// lstVw_ActorsList.Items[i].BackColor = (Color)c.ConvertFromString("#dedeff");
//}
//else
//{
// lstVw_ActorsList.Items[i].BackColor = (Color)c.ConvertFromString("#bfbff7");
//}
if (lstVw_ActorsList.Items[i].SubItems[10].Text == "Deactivated")
{
//Use of gray color.
lstVw_ActorsList.Items[i].BackColor = (Color)c.ConvertFromString("#dadada");
}
}
}