当前位置: 首页>>代码示例>>C#>>正文


C# Drawing.ColorConverter类代码示例

本文整理汇总了C#中System.Drawing.ColorConverter的典型用法代码示例。如果您正苦于以下问题:C# ColorConverter类的具体用法?C# ColorConverter怎么用?C# ColorConverter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ColorConverter类属于System.Drawing命名空间,在下文中一共展示了ColorConverter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ColorConverter2

    //*************************************************************************
    //  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();
    }
开发者ID:2014-sed-team3,项目名称:term-project,代码行数:37,代码来源:ColorConverter2.cs

示例2: 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");
            }
        }
开发者ID:ehershey,项目名称:development,代码行数:27,代码来源:GradientFillConverter.cs

示例3: 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 };
        }
开发者ID:TheInvoker,项目名称:Card,代码行数:31,代码来源:SquareDetector.cs

示例4: 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");
            }
        }
开发者ID:KelvinCoding,项目名称:masterwork-dwarf-fortress,代码行数:28,代码来源:CaptionGradientConverter.cs

示例5: 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]);
        }
开发者ID:helloworld89,项目名称:2048Console,代码行数:25,代码来源:OutPutHelper.cs

示例6: 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");
            }
        }
开发者ID:KelvinCoding,项目名称:masterwork-dwarf-fortress,代码行数:26,代码来源:GradientTabConverter.cs

示例7: ToString

 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);
 }
开发者ID:KelvinCoding,项目名称:masterwork-dwarf-fortress,代码行数:7,代码来源:GradientTabConverter.cs

示例8: Generate

        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();
        }
开发者ID:squla,项目名称:projekt-zespolowy,代码行数:31,代码来源:AvatarGenerator.cs

示例9: ToString

 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));
 }
开发者ID:KelvinCoding,项目名称:masterwork-dwarf-fortress,代码行数:7,代码来源:ButtonsCaptionConverter.cs

示例10: 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");
            }
        }
开发者ID:KelvinCoding,项目名称:masterwork-dwarf-fortress,代码行数:26,代码来源:ButtonsCaptionConverter.cs

示例11: ConvertFromString

		/// <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");
					}
		}	
开发者ID:jbautistam,项目名称:BauXmppMessenger,代码行数:29,代码来源:StyleBauControlConverter.cs

示例12: 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);
        }
开发者ID:verebes,项目名称:xml_form_editor,代码行数:34,代码来源:StaticLabel.cs

示例13: 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);
                    }
                }
            }
        }
开发者ID:wshanshan,项目名称:DDD,代码行数:57,代码来源:ThresholdDataSet.cs

示例14: ToString

        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);
        }
开发者ID:KelvinCoding,项目名称:masterwork-dwarf-fortress,代码行数:9,代码来源:HatcherConverter.cs

示例15: sbColorPickerCombo

 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;
 }
开发者ID:softballsolutions,项目名称:softballsolutions,代码行数:9,代码来源:sbColorPickerCombo.cs


注:本文中的System.Drawing.ColorConverter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。