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


C# ColorConverter.ConvertFromInvariantString方法代码示例

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


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

示例1: repositoryItemColorEdit1_Validating

 private void repositoryItemColorEdit1_Validating(object sender, CancelEventArgs e)
 {
     DevExpress.XtraEditors.TextEdit tx = (DevExpress.XtraEditors.TextEdit)sender;
     if (tx.Text.Length > 0)
     {
         ColorConverter cc = new ColorConverter();
         Color obj= (Color)cc.ConvertFromInvariantString(tx.Text);
         _obj.Color = ColorTranslator.ToOle(obj);
     }
 }
开发者ID:EdgarEDT,项目名称:myitoppsp,代码行数:10,代码来源:FrmBaseColorDialog.cs

示例2: HandleEscSeq2

			private void HandleEscSeq2(PegNode node, StyleContext context, StructuralGlyph parent)
			{
				int posBeg = node.match_.posBeg_;
				var childNode = node.child_;

				if (childNode == null)
					throw new ArgumentNullException("childNode");

				string escHeader = _sourceText.Substring(posBeg, childNode.match_.posBeg_ - posBeg);

				switch (escHeader.ToLowerInvariant())
				{
					case @"\=(":
						{
							var newParent = new SubSuperScript();
							newParent.Style = context;
							parent.Add(newParent);

							var newContext = context.Clone();
							newContext.ScaleFont(0.65);
							VisitNode(childNode, newContext, newParent);
						}
						break;

					case @"\p(":
						{
							double val;
							string s1 = GetText(childNode).Trim();
							var newContext = context.Clone();
							string numberString;
							Altaxo.Serialization.LengthUnit lengthUnit;

							if (s1.EndsWith("%"))
							{
								numberString = s1.Substring(0, s1.Length - 1);
								if (double.TryParse(numberString, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out val))
								{
									newContext.BaseFontId = context.BaseFontId.WithSize(context.BaseFontId.Size * val / 100);
									newContext.ScaleFont(val / 100);
								}
							}
							else if (Altaxo.Serialization.LengthUnit.TryParse(s1, out lengthUnit, out numberString) &&
								double.TryParse(numberString, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out val)
								)
							{
								double newSize = val * (double)(lengthUnit.UnitInMeter / Altaxo.Serialization.LengthUnit.Point.UnitInMeter);
								newContext.BaseFontId = context.BaseFontId.WithSize(newSize);
								newContext.FontId = context.FontId.WithSize(newSize);
							}
							else if (double.TryParse(s1, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out val)
								)
							{
								double newSize = val;
								newContext.BaseFontId = context.BaseFontId.WithSize(newSize);
								newContext.FontId = context.FontId.WithSize(newSize);
							}
							VisitNode(childNode.next_, newContext, parent);
						}
						break;

					case @"\c(":
						{
							string s1 = GetText(childNode).Trim();
							var newContext = context.Clone();
							var conv = new ColorConverter();

							try
							{
								object result = conv.ConvertFromInvariantString(s1);
								newContext.brush = new SolidBrush((Color)result);
							}
							catch (Exception)
							{
							}

							VisitNode(childNode.next_, newContext, parent);
						}
						break;

					case @"\l(":
						{
							string s1 = GetText(childNode);
							string s2 = GetText(childNode.next_);
							int plotNumber, plotLayer;
							if (int.TryParse(s1, out plotLayer) && int.TryParse(s2, out plotNumber))
							{
								parent.Add(new PlotSymbol(context, plotNumber, plotLayer));
							}
						}
						break;

					case @"\%(":
						{
							string s1 = GetText(childNode);
							string s2 = GetText(childNode.next_);
							int plotNumber, plotLayer;
							if (int.TryParse(s1, out plotLayer) && int.TryParse(s2, out plotNumber))
							{
								parent.Add(new PlotName(context, plotNumber, plotLayer));
							}
//.........这里部分代码省略.........
开发者ID:Altaxo,项目名称:Altaxo,代码行数:101,代码来源:TextGraphic_TreeWalker.cs

示例3: ConvertFromInvariantString_NotNumber

 public void ConvertFromInvariantString_NotNumber()
 {
     var conv = new ColorConverter();
     var ex = Assert.Throws<Exception>(() =>
     {
         conv.ConvertFromInvariantString("hello");
     });
     Assert.NotNull(ex.InnerException);
     Assert.IsType<FormatException>(ex.InnerException);
 }
开发者ID:geoffkizer,项目名称:corefx,代码行数:10,代码来源:ColorConverterTests.cs

示例4: return

    TryConvertFromInvariantString
    (
        String theString,
        ColorConverter colorConverter,
        out Color color
    )
    {
        Debug.Assert(colorConverter != null);
        Debug.Assert(theString != null);

        color = Color.Empty;

        // Remove spaces in named colors, so that "Light Blue" becomes
        // "LightBlue", for example.

        theString = theString.Replace(" ", String.Empty);

        if (theString.Length == 0)
        {
            // ColorConverter converts an empty string to Color.Black.  Bypass
            // ColorConverter.

            return (false);
        }

        try
        {
            color = (Color)colorConverter.ConvertFromInvariantString(
                theString);
        }
        catch (Exception)
        {
            // (Format errors raise a System.Exception with an inner exception
            // of type FormatException.  Go figure.)

            return (false);
        }

        return (true);
    }
开发者ID:2014-sed-team3,项目名称:term-project,代码行数:40,代码来源:ColorUtil.cs

示例5: ConvertFromInvariantString_Name

 public void ConvertFromInvariantString_Name(string name)
 {
     var conv = new ColorConverter();
     var color = Color.FromName(name);
     Assert.Equal(color, (Color) conv.ConvertFromInvariantString(name));
 }
开发者ID:geoffkizer,项目名称:corefx,代码行数:6,代码来源:ColorConverterTests.cs

示例6: ConvertFromInvariantString_Invalid

 public void ConvertFromInvariantString_Invalid()
 {
     var conv = new ColorConverter();
     Assert.Throws<ArgumentException>(() =>
     {
         conv.ConvertFromInvariantString("1, 2, 3, 4, 5");
     });
 }
开发者ID:geoffkizer,项目名称:corefx,代码行数:8,代码来源:ColorConverterTests.cs

示例7: ConvertFromInvariantString

 public void ConvertFromInvariantString(int a, int r, int g, int b)
 {
     var conv = new ColorConverter();
     var color = (Color) conv.ConvertFromInvariantString($"{a}, {r}, {g}, {b}");
     Assert.Equal(a, color.A);
     Assert.Equal(r, color.R);
     Assert.Equal(g, color.G);
     Assert.Equal(b, color.B);
 }
开发者ID:geoffkizer,项目名称:corefx,代码行数:9,代码来源:ColorConverterTests.cs

示例8: AssertValid

    ConvertFrom
    (
        ITypeDescriptorContext context,
        CultureInfo culture,
        Object value
    )
    {
        Debug.Assert(value != null);
        Debug.Assert(value is String);
        AssertValid();

        ColorColumnAutoFillUserSettings oColorColumnAutoFillUserSettings =
            new ColorColumnAutoFillUserSettings();

        ColorConverter oColorConverter = new ColorConverter();

        String [] asStrings = ( (String)value ).Split( new Char[] {'\t'} );

        Debug.Assert(asStrings.Length >= 7);

        oColorColumnAutoFillUserSettings.UseSourceNumber1 =
            Boolean.Parse( asStrings[0] );

        oColorColumnAutoFillUserSettings.UseSourceNumber2 =
            Boolean.Parse( asStrings[1] );

        oColorColumnAutoFillUserSettings.SourceNumber1 =
            MathUtil.ParseCultureInvariantDouble( asStrings[2] );

        oColorColumnAutoFillUserSettings.SourceNumber2 =
            MathUtil.ParseCultureInvariantDouble(asStrings[3]);

        oColorColumnAutoFillUserSettings.DestinationColor1 =
            (Color)oColorConverter.ConvertFromInvariantString( asStrings[4] );

        oColorColumnAutoFillUserSettings.DestinationColor2 =
            (Color)oColorConverter.ConvertFromInvariantString( asStrings[5] );

        oColorColumnAutoFillUserSettings.IgnoreOutliers =
            Boolean.Parse( asStrings[6] );

        // The UseLogs property wasn't added until NodeXL version 1.0.1.92.

        oColorColumnAutoFillUserSettings.UseLogs =
            (asStrings.Length > 7) ? Boolean.Parse( asStrings[7] ) : false;

        // The SourceColumnContainsNumbers property wasn't added until NodeXL
        // version 1.0.1.153.

        oColorColumnAutoFillUserSettings.SourceColumnContainsNumbers =
            (asStrings.Length > 8) ? Boolean.Parse( asStrings[8] ) : true;

        return (oColorColumnAutoFillUserSettings);
    }
开发者ID:2014-sed-team3,项目名称:term-project,代码行数:54,代码来源:ColorColumnAutoFillUserSettings.cs

示例9: ColorConverter

    ConvertFromString
    (
        String [] asFields,
        Int32 iStartIndex
    )
    {
        Debug.Assert(asFields != null);
        Debug.Assert(iStartIndex >= 0);

        iStartIndex = base.ConvertFromString(asFields, iStartIndex);

        Debug.Assert(iStartIndex + 3 < asFields.Length);

        ColorConverter oColorConverter = new ColorConverter();

        m_bSourceColumnContainsNumbers =
            (Boolean)( new System.ComponentModel.BooleanConverter() ).
                ConvertFromInvariantString( asFields[iStartIndex + 0] );

        m_oDestinationColor1 =
            (Color)oColorConverter.ConvertFromInvariantString(
                asFields[iStartIndex + 1] );

        m_oDestinationColor2 =
            (Color)oColorConverter.ConvertFromInvariantString(
                asFields[iStartIndex + 2] );

        m_oCategoryNames = asFields[iStartIndex + 3].Split(
            PerWorkbookSettings.SubFieldSeparator);

        // Note:
        //
        // If another field is added here, the total expected field count in 
        // AutoFillWorkbookResults.ConvertFromString() must be increased.

        return (iStartIndex + 4);
    }
开发者ID:2014-sed-team3,项目名称:term-project,代码行数:37,代码来源:AutoFillColorColumnResults.cs

示例10: AssertValid

    ConvertFrom
    (
        ITypeDescriptorContext context,
        CultureInfo culture,
        Object value
    )
    {
        Debug.Assert(value != null);
        Debug.Assert(value is String);
        AssertValid();

        LabelUserSettings oLabelUserSettings = new LabelUserSettings();

        String [] asStrings = ( (String)value ).Split( new Char[] {'\t'} );

        Debug.Assert(asStrings.Length >= 5);

        ColorConverter oColorConverter = new ColorConverter();

        oLabelUserSettings.Font = (Font)
            ( new FontConverter() ).ConvertFromInvariantString(asStrings[0] );

        oLabelUserSettings.VertexLabelFillColor = (Color)
            oColorConverter.ConvertFromInvariantString(asStrings[1] );

        oLabelUserSettings.VertexLabelPosition = (VertexLabelPosition)
            Enum.Parse( typeof(VertexLabelPosition), asStrings[2] );

        oLabelUserSettings.VertexLabelMaximumLength =
            MathUtil.ParseCultureInvariantInt32( asStrings[3] );

        oLabelUserSettings.EdgeLabelMaximumLength =
            MathUtil.ParseCultureInvariantInt32(asStrings[4]);

        if (asStrings.Length > 5)
        {
            // Edge label text color wasn't added until version 1.0.1.154.

            oLabelUserSettings.EdgeLabelTextColor = (Color)
                oColorConverter.ConvertFromInvariantString(asStrings[5] );
        }

        if (asStrings.Length > 6)
        {
            // Vertex label wrapping wasn't added until version 1.0.1.175.

            oLabelUserSettings.VertexLabelWrapText =
                Boolean.Parse( asStrings[6] );

            oLabelUserSettings.VertexLabelWrapMaxTextWidth =
                MathUtil.ParseCultureInvariantDouble( asStrings[7] );
        }

        if (asStrings.Length > 8)
        {
            // Group label text color and alpha weren't added until version
            // 1.0.1.190.

            oLabelUserSettings.GroupLabelTextColor = (Color)
                oColorConverter.ConvertFromInvariantString( asStrings[8] );

            oLabelUserSettings.GroupLabelTextAlpha =
                MathUtil.ParseCultureInvariantSingle( asStrings[9] );
        }

        if (asStrings.Length > 10)
        {
            // Group label position wasn't added until version 1.0.1.215.

            oLabelUserSettings.GroupLabelPosition = (VertexLabelPosition)
                Enum.Parse( typeof(VertexLabelPosition), asStrings[10] );
        }

        return (oLabelUserSettings);
    }
开发者ID:2014-sed-team3,项目名称:term-project,代码行数:75,代码来源:LabelUserSettings.cs

示例11: ColorConverter

        /// <summary>
        /// Generates an object from its XML representation.
        /// </summary>
        /// <param name="reader">The <see cref="T:System.Xml.XmlReader"/> stream from which the object is deserialized.</param>
        void IXmlSerializable.ReadXml(System.Xml.XmlReader reader)
        {
            ColorConverter conv = new ColorConverter();

            while (reader.Read())
            {
                // end element
                if (reader.NodeType == System.Xml.XmlNodeType.EndElement &&
                    reader.Name == "TimeSaverSettings")
                    break;

                if (reader.NodeType == System.Xml.XmlNodeType.Element &&
                    !reader.IsEmptyElement)
                {
                    string text = reader.ReadString();
                    switch (reader.Name)
                    {
                        case "TextColor":
                            TextColor = (Color)conv.ConvertFromInvariantString(text);
                            break;

                        case "BackColor":
                            BackColor = (Color)conv.ConvertFromInvariantString(text);
                            break;

                        case "DisplayMode":
                            if (Enum.IsDefined(typeof(DisplayMode), text))
                                DisplayMode = (DisplayMode)Enum.Parse(typeof(DisplayMode), text, true);
                            break;

                        case "BlinkTimeSeparator":
                            bool blink;
                            if (bool.TryParse(text, out blink))
                                BlinkTimeSeparator = blink;
                            break;

                        case "UseUpperCase":
                            bool upperCase;
                            if (bool.TryParse(text, out upperCase))
                                UseUpperCase = upperCase;
                            break;
                    }
                }
            }
        }
开发者ID:bornste,项目名称:TimeSaver,代码行数:49,代码来源:Settings.cs


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