private string ToString(object value) { var buttons = (ButtonsCaption)value; // Gelen object tipimizi ButtonsCaption tipine dönüştürüyoruz ve ayıklama işlemine başlıyoruz. var converter = new ColorConverter(); return String.Format("{0}, {1}", converter.ConvertToString(buttons.ActiveCaptionButtonsColor), converter.ConvertToString(buttons.InactiveCaptionButtonsColor)); }
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"); } }
static void Main(string[] args) { //Command line args are as follows (color args will be hex value): //<Analyzation directory> <Output directory> <color 1> ... <color n> List <string> argList = new List <string>(args); //Check for keyword parameter string keyword = GetSpecificParameter(Constants.Parameters.Keyword, ref argList); //Check for regex parameter string regex = GetSpecificParameter(Constants.Parameters.Regex, ref argList); if (argList.Count > 2) { string analyzeDirectory = argList[0]; string outputDirectory = argList[1]; //Check to make sure the analysis directory exists if (!Directory.Exists(analyzeDirectory)) { //Exit the program since the folder given to analyze does not exist } //Iterate through args 3 to n to get all the colors to look for DRAW.ColorConverter colConverter = new DRAW.ColorConverter(); for (int i = 2; i < argList.Count; i++) { string name, analyzerDLL, analyzerID; DRAW.Color color = new DRAW.Color(); GetColorArgParts (argList[i], out name, out color, out analyzerDLL, out analyzerID); if (string.IsNullOrEmpty(name)) { name = i.ToString(); } m_colorDict.Add(name, color); if (!string.IsNullOrEmpty(analyzerDLL) && !string.IsNullOrEmpty(analyzerID)) { AddToAnalyzerDict(color, analyzerDLL, analyzerID); } } AnalyzeDirectory(analyzeDirectory, outputDirectory, regex, keyword); } else { //Check if the user is asking for help if (argList.Contains(Constants.Parameters.Help) || argList.Contains(Constants.Parameters.HelpAlternate)) { PrintHelpInfo(); } //Do some analysis of the args passed-in in order to provide good user //feedback } }
public byte[] Generate(string username) { var avatarString = $"{username[0]}".ToUpper(); var randomIndex = new Random().Next(0, _backgroundColours.Count - 1); var bgColour = _backgroundColours[randomIndex]; var bmp = new Bitmap(32, 32); var sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; var font = new Font("Arial", 32, FontStyle.Bold, GraphicsUnit.Pixel); var graphics = Graphics.FromImage(bmp); var convertFromString = new ColorConverter().ConvertFromString("#" + bgColour); if (convertFromString != null) { graphics.Clear((Color)convertFromString); } graphics.SmoothingMode = SmoothingMode.AntiAlias; graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; graphics.DrawString(avatarString, font, new SolidBrush(Color.WhiteSmoke), new RectangleF(0, 0, 32, 32), sf); graphics.Flush(); var ms = new MemoryStream(); bmp.Save(ms, ImageFormat.Png); return ms.ToArray(); }
public object ReadYaml(IParser parser, Type type) { var color = parser.Expect <Scalar>(); var converter = new System.Drawing.ColorConverter(); return((Color)converter.ConvertFromInvariantString(color.Value)); }
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"); } }
/// <summary> /// Obtiene un estilo a partir de una cadena /// </summary> private StyleBauControl ConvertFromString(object objValue) { string [] arrStrValues = ((string) objValue).Split(','); ColorConverter objConverter = new ColorConverter(); StyleBauControl objStyle = new StyleBauControl(); try { // Obtiene la cadena formateada con los valores numéricos objStyle.RoundCorners = int.Parse(arrStrValues[0]); objStyle.AngleCorners = int.Parse(arrStrValues[1]); objStyle.ShadowThickness = int.Parse(arrStrValues[2]); objStyle.BorderWidth = int.Parse(arrStrValues[3]); // Obtiene la cadena formateada con los colores objStyle.BorderColor = (Color) objConverter.ConvertFromString(arrStrValues[4]); objStyle.BackgroundColor = (Color) objConverter.ConvertFromString(arrStrValues[5]); objStyle.BackgroundGradientColor = (Color) objConverter.ConvertFromString(arrStrValues[6]); objStyle.ShadowColor = (Color) objConverter.ConvertFromString(arrStrValues[7]); objStyle.ForeColor = (Color) objConverter.ConvertFromString(arrStrValues[8]); // Obtiene la cadena formateada con el modo del gradiante objStyle.GradientMode = (StyleBauControl.GroupBoxGradientMode) int.Parse(arrStrValues[9]); // Devuelve el estilo return objStyle; } catch { throw new ArgumentException("Could not convert the value"); } }
//************************************************************************* // Constructor: ColorConverter2() // /// <summary> /// Initializes a new instance of the <see cref="ColorConverter2" /> class. /// </summary> //************************************************************************* public ColorConverter2() { m_oColorConverter = new System.Drawing.ColorConverter(); // System.Drawing.ColorConverter.ConvertToString() converts a common // Color, such as (255,0,0), to its common name, such as "Red", only if // the Color was originally created from a name. Otherwise, it // converts the color to the string "255, 0, 0". To make colors more // readable, this class explicitly converts common colors to their // names using a dictionary lookup. m_oCommonColorNames = new Dictionary <Color, String>(); m_oCommonColorNames.Add(Color.FromArgb(0, 0, 0), "Black"); m_oCommonColorNames.Add(Color.FromArgb(255, 255, 255), "White"); m_oCommonColorNames.Add(Color.FromArgb(0, 0, 255), "Blue"); m_oCommonColorNames.Add(Color.FromArgb(0, 255, 0), "Lime"); m_oCommonColorNames.Add(Color.FromArgb(255, 0, 0), "Red"); m_oCommonColorNames.Add(Color.FromArgb(0, 255, 255), "Cyan"); m_oCommonColorNames.Add(Color.FromArgb(255, 255, 0), "Yellow"); m_oCommonColorNames.Add(Color.FromArgb(255, 0, 255), "Magenta"); m_oCommonColorNames.Add(Color.FromArgb(255, 165, 0), "Orange"); m_oCommonColorNames.Add(Color.FromArgb(0, 128, 0), "Green"); AssertValid(); }
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"); } }
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 }; }
public static Color ConvertColor(string colorstr, Color defcolor) { if (string.IsNullOrEmpty(colorstr)) { return(defcolor); } Color retcolor = new Color(); System.Drawing.ColorConverter colConvert = new System.Drawing.ColorConverter(); try { retcolor = (Color)colConvert.ConvertFromString("#" + colorstr); } catch { try { retcolor = (Color)colConvert.ConvertFromString(colorstr); } catch { retcolor = defcolor; } } return(retcolor); }
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]); }
//************************************************************************* // Constructor: ColorConverter2() // /// <summary> /// Initializes a new instance of the <see cref="ColorConverter2" /> class. /// </summary> //************************************************************************* public ColorConverter2() { m_oColorConverter = new System.Drawing.ColorConverter(); // System.Drawing.ColorConverter.ConvertToInvariantString() converts a // common Color, such as (255,0,0), to its common name, such as "Red", // only if the Color was originally created from a name. Otherwise, it // converts the color to the string "255, 0, 0". To make colors more // readable, this class explicitly converts common colors to their // names using a dictionary lookup. m_oCommonColorNames = new Dictionary<Color, String>(); m_oCommonColorNames.Add(Color.FromArgb( 0, 0, 0), "Black"); m_oCommonColorNames.Add(Color.FromArgb(255, 255, 255), "White"); m_oCommonColorNames.Add(Color.FromArgb( 0, 0, 255), "Blue"); m_oCommonColorNames.Add(Color.FromArgb( 0, 255, 0), "Lime"); m_oCommonColorNames.Add(Color.FromArgb(255, 0, 0), "Red"); m_oCommonColorNames.Add(Color.FromArgb(0, 255, 255), "Cyan"); m_oCommonColorNames.Add(Color.FromArgb(255, 255, 0), "Yellow"); m_oCommonColorNames.Add(Color.FromArgb(255, 0, 255), "Magenta"); m_oCommonColorNames.Add(Color.FromArgb(255, 165, 0), "Orange"); m_oCommonColorNames.Add(Color.FromArgb(0, 128, 0), "Green"); AssertValid(); }
private string ToString(object value) { var gradient = value as GradientTab; // Gelen object tipimizi GradientTab tipine dönüştürüyoruz ve ayıklama işlemine başlıyoruz. var converter = new ColorConverter(); return String.Format("{0}, {1}, {2}, {3}, {4}, {5}", converter.ConvertToString(gradient.ColorStart), converter.ConvertToString(gradient.ColorEnd), gradient.GradientStyle, converter.ConvertToString(gradient.TabPageTextColor), converter.ConvertToString(gradient.TabPageSelectedTextColor), gradient.SelectedTabFontStyle); }
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"); } }
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); }
public void WriteYaml(IEmitter emitter, object value, Type type) { var color = (Color)value; var converter = new System.Drawing.ColorConverter(); var str = converter.ConvertToInvariantString(color); emitter.Emit(new Scalar(str)); }
public sbColorPickerCombo(ComboBox comboBox) { ColorConverter cc = new ColorConverter(); ICollection colorCollection = cc.GetStandardValues(); this.colorArray = new Color[colorCollection.Count]; colorCollection.CopyTo(colorArray, 0); this.InitializeList(comboBox); this.SelectedIndexChangedEventEnabled = true; }
private string ToString(object value) { Hatcher hatch = value as Hatcher; // Gelen object tipimizi Hatcher tipine dönüştürüyoruz ve ayıklama işlemine başlıyoruz. ColorConverter converter = new ColorConverter(); return String.Format("{0}, {1}, {2}", converter.ConvertToString(hatch.ForeColor), converter.ConvertToString(hatch.BackColor), hatch.HatchStyle); }
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); } } } }
public void SetUp () { col = Color.FromArgb (10, 20, 30); colStr = string.Format ("10{0} 20{0} 30", CultureInfo.CurrentCulture.TextInfo.ListSeparator); colStrInvariant = string.Format ("10{0} 20{0} 30", CultureInfo.InvariantCulture.TextInfo.ListSeparator); colnamed = Color.ForestGreen; colnamedStr = "ForestGreen"; colconv = (ColorConverter) TypeDescriptor.GetConverter (col); }
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(); }
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."); } }
/// <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; }
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); }
public LoginWindow() { InitializeComponent(); //this.emailTextBox.Text = "*****@*****.**"; //this.passwordTextBox.Text = "ion"; ColorConverter conv = new ColorConverter(); //CornerRounder.Round(emailTextBox); //CornerRounder.Round(parolaTextBox); //CornerRounder.Round(logareButton); //CornerRounder.Round(iesireButton); loginButton.FlatAppearance.BorderColor = Color.FromArgb(0, 255, 255, 255); exitButton.FlatAppearance.BorderColor = Color.FromArgb(0, 255, 255, 255); }
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]; }
public static void ChangeColor(string hexColorCode) { var convertFromString = new ColorConverter().ConvertFromString(hexColorCode); if (convertFromString != null) { var color = (Color)convertFromString; var imagePath = Path.GetTempFileName(); DrawFilledRectangle(3840, 2160, new SolidBrush(color)).Save(imagePath, ImageFormat.Jpeg); File.Copy(Config.BakPriFileLocation, TempPriFile, true); LogonPriEditor.ModifyLogonPri(TempPriFile, NewPriLocation, imagePath); } File.Copy(NewPriLocation, Config.PriFileLocation, true); }
public static Color FromHtml(string htmlColor) { if ((htmlColor == null) || (htmlColor.Length == 0)) return Color.Transparent; switch (htmlColor.ToLowerInvariant ()) { case "lightgrey": return Color.LightGray; } var _conv = new ColorConverter(); return ColorConverter.StaticConvertFromString(null, htmlColor, null); //TypeConverter converter = TypeDescriptor.GetConverter (typeof (Color)); //return (Color)converter.ConvertFromString(htmlColor); }
/// <summary> /// 返回表示对象的字符串 /// </summary> /// <returns>字符串</returns> public override string ToString() { System.Drawing.ColorConverter cc = new System.Drawing.ColorConverter(); System.Text.StringBuilder str = new StringBuilder(); str.Append(intDashStyle.ToString()); str.Append(" " + System.Drawing.ColorTranslator.ToHtml(intColor)); str.Append(" " + fWidth); if (this.MiterLimit != 10f) { str.Append(" MiterLimit:" + this.MiterLimit); } if (this.Alignment != PenAlignment.Center) { str.Append(" " + this.Alignment); } return(str.ToString()); }
/// <summary> /// Extracts the individual parts of a color argument /// </summary> /// <param name="arg">The argument</param> /// <param name="name">The name of the analysis data</param> /// <param name="color">The color source of this analysis</param> /// <param name="analyzerDLL">The name of the analyzer component</param> private static void GetColorArgParts(string arg, out string name, out DRAW.Color color, out string analyzerDLL, out string analyzerID) { string colorStr = string.Empty; name = string.Empty; analyzerDLL = string.Empty; analyzerID = string.Empty; if (arg.ElementAt(0) == '-' && arg.Contains("=") && arg.Contains("|")) { //This argument contains a name for this color, get both string[] thisArgElements = arg.Split ("-=|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); name = thisArgElements[0]; colorStr = thisArgElements[1]; analyzerDLL = thisArgElements[2]; analyzerID = thisArgElements[3]; } else { colorStr = arg; } //Try to instantiate the color from the raw color string in case //it's a name color = DRAW.Color.FromName(colorStr); //Instantiate a color converter DRAW.ColorConverter colConverter = new DRAW.ColorConverter(); //Check if this is a valid color if (color.Equals(DRAW.Color.FromName("Invalid"))) { //Sanitize color string if (colorStr.ElementAt(0) != '#') { colorStr = "#" + colorStr; } color = (DRAW.Color)colConverter.ConvertFromString(colorStr); } }
/// <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; }
/// <summary> /// Convierte un valor a una cadena /// </summary> public new string ConvertToString(object objValue) { StyleBauControl objStyle = (StyleBauControl) objValue; ColorConverter objConverter = new ColorConverter(); string strConvert; // Obtiene la cadena formateada con los valores numéricos strConvert = objStyle.RoundCorners.ToString() + ","; strConvert = objStyle.AngleCorners.ToString() + ","; strConvert += objStyle.ShadowThickness.ToString() + ","; strConvert += objStyle.BorderWidth.ToString() + ","; // Obtiene la cadena formateada con los colores strConvert += objConverter.ConvertToString(objStyle.BorderColor) + ","; strConvert += objConverter.ConvertToString(objStyle.BackgroundColor) + ","; strConvert += objConverter.ConvertToString(objStyle.BackgroundGradientColor) + ","; strConvert += objConverter.ConvertToString(objStyle.ShadowColor) + ","; strConvert += objConverter.ConvertToString(objStyle.ForeColor) + ","; // Obtiene la cadena formateada con el modo del gradiante strConvert += ((int) objStyle.GradientMode).ToString(); // Devuelve la cadena return strConvert; }
public void SunnyDayScenario() { IDictionary converters = new Hashtable(); Type dateTimeType = typeof(DateTime); DateTimeConverter dateTimeConverter = new DateTimeConverter(); Type colorType = typeof(Color); ColorConverter colorConverter = new ColorConverter(); converters.Add(dateTimeType, dateTimeConverter); converters.Add(colorType, colorConverter); factory.RegisterCustomConverter(dateTimeType, dateTimeConverter); factory.RegisterCustomConverter(colorType, colorConverter); mocks.ReplayAll(); CustomConverterConfigurer config = new CustomConverterConfigurer(); config.CustomConverters = converters; config.PostProcessObjectFactory(factory); mocks.VerifyAll(); }
public LoginWindow() { InitializeComponent(); this.emailTextBox.Text = "*****@*****.**"; this.parolaTextBox.Text = "ion"; conexiune = new Conexiune(); ColorConverter conv = new ColorConverter(); //CornerRounder.Round(emailTextBox); //CornerRounder.Round(parolaTextBox); //CornerRounder.Round(logareButton); //CornerRounder.Round(iesireButton); logareButton.FlatAppearance.BorderColor = Color.FromArgb(0, 255, 255, 255); iesireButton.FlatAppearance.BorderColor = Color.FromArgb(0, 255, 255, 255); img = new Image[8]; img[0] = DowMediaApplication.Properties.Resources.Rotate0 as Image; img[1] = DowMediaApplication.Properties.Resources.Rotate1 as Image; img[2] = DowMediaApplication.Properties.Resources.Rotate2 as Image; img[3] = DowMediaApplication.Properties.Resources.Rotate3 as Image; img[4] = DowMediaApplication.Properties.Resources.Rotate4 as Image; img[5] = DowMediaApplication.Properties.Resources.Rotate5 as Image; img[6] = DowMediaApplication.Properties.Resources.Rotate6 as Image; img[7] = DowMediaApplication.Properties.Resources.Rotate7 as Image; }
public ICommand CreateCommand(string stringCommand) { _wordsBrushes = new List<SolidBrush>(); var pattern = "colors:<.+>"; var converter = new ColorConverter(); if (!Regex.IsMatch(stringCommand, pattern)) throw new Exception(); stringCommand = stringCommand.Substring(8, stringCommand.Length - 9); var splited = stringCommand.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries); Color tempColor; foreach (var color in splited) { try { tempColor = (Color)converter.ConvertFromString(color); } catch (Exception) { throw new Exception("Can not convert" + color); } _wordsBrushes.Add(new SolidBrush(tempColor)); } return this; }
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"); } } }
/// <summary> /// 得到二维码 /// </summary> /// <param name="qRCodeControl"></param> /// <param name="content">二维码内容</param> /// <param name="icon">二维码图标</param> /// <returns></returns> private static ImageSource GetQRCodeImage(QRCodeControl qrCodeControl) { System.Drawing.ColorConverter colorConverter = new System.Drawing.ColorConverter(); using (QRCodeGenerator qrGenerator = new QRCodeGenerator()) { using (QRCodeData qRCodeData = qrGenerator.CreateQrCode(qrCodeControl.QrCodeContent, QRCodeGenerator.ECCLevel.L)) { using (QRCode qrCode = new QRCode(qRCodeData)) { Bitmap codeImage = qrCode.GetGraphic( qrCodeControl.QrCodePixelsPerModule, (System.Drawing.Color)colorConverter.ConvertFromString(qrCodeControl.Foreground.ToString()), System.Drawing.Color.FromName(((SolidColorBrush)qrCodeControl.Background).Color.ToString()), ImageBitmapConverter.ToBitmap(qrCodeControl.QrCodeIcon), qrCodeControl.QrCodeIconSizePercent, qrCodeControl.QrCodeIconBorderWidth); qrCodeControl.QRCodeImage = ImageBitmapConverter.ToImageSource(codeImage); //qrCodeControl.QRCodeImage = Imaging.CreateBitmapSourceFromHBitmap(codeImage.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); return(qrCodeControl.QRCodeImage); } } } }
public System.Drawing.Brush ConvertToBrush(string color) { System.Drawing.ColorConverter mConverter = new System.Drawing.ColorConverter(); System.Drawing.Brush mBrush = new System.Drawing.SolidBrush((System.Drawing.Color)mConverter.ConvertFrom(color)); return(mBrush); }