當前位置: 首頁>>代碼示例>>C#>>正文


C# ColorConverter.ConvertFromString方法代碼示例

本文整理匯總了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");
            }
        }
開發者ID:ehershey,項目名稱:development,代碼行數:27,代碼來源:GradientFillConverter.cs

示例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");
            }
        }
開發者ID:KelvinCoding,項目名稱:masterwork-dwarf-fortress,代碼行數:26,代碼來源:GradientTabConverter.cs

示例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");
            }
        }
開發者ID:KelvinCoding,項目名稱:masterwork-dwarf-fortress,代碼行數:26,代碼來源:ButtonsCaptionConverter.cs

示例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);
        }
開發者ID:verebes,項目名稱:xml_form_editor,代碼行數:34,代碼來源:StaticLabel.cs

示例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);
                    }
                }
            }
        }
開發者ID:wshanshan,項目名稱:DDD,代碼行數:57,代碼來源:ThresholdDataSet.cs

示例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];
        }
開發者ID:bleemus,項目名稱:YATP,代碼行數:13,代碼來源:Matcher.cs

示例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 };
        }
開發者ID:TheInvoker,項目名稱:Card,代碼行數:31,代碼來源:SquareDetector.cs

示例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]);
        }
開發者ID:helloworld89,項目名稱:2048Console,代碼行數:25,代碼來源:OutPutHelper.cs

示例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();
        }
開發者ID:tomfuru,項目名稱:StarlitTwit,代碼行數:11,代碼來源:SerializableColor.cs

示例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;
        }
開發者ID:yunchenglk,項目名稱:XY.Application,代碼行數:25,代碼來源:RandomCode.cs

示例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;
 }
開發者ID:ZixiangBoy,項目名稱:YongERP,代碼行數:17,代碼來源:Common.cs

示例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.");
     }
 }
開發者ID:nebtrx,項目名稱:sidewired,代碼行數:12,代碼來源:ColorString.cs

示例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");
            }
        }
開發者ID:KelvinCoding,項目名稱:masterwork-dwarf-fortress,代碼行數:28,代碼來源:CaptionGradientConverter.cs

示例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);
        }
開發者ID:jesszgc,項目名稱:VideoConvert,代碼行數:13,代碼來源:SSAReader.cs

示例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");
                }
            }
        }
開發者ID:walidBelfadel,項目名稱:MARS_project,代碼行數:24,代碼來源:frm_SearchActor.cs


注:本文中的System.Drawing.ColorConverter.ConvertFromString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。