FromName() public static method

public static FromName ( string name ) : Color
name string
return Color
Ejemplo n.º 1
0
        private void SmokeColorInit()
        {
            Color tmp = Color.FromName(SettingsHolder.Instance.enmSmokeColor.ToString());

            if (tmp.IsNamedColor)
            {
                if (tmp != Color.White && tmp != Color.Black)
                {
                    MessageBox.Show("Invalid smoke color");
                    return;
                }

                if (tmp == Color.White)
                {
                    m_color     = 255;
                    m_direction = -1;
                }
                else
                {
                    m_color     = 0;
                    m_direction = 1;
                }
            }
            else
            {
                MessageBox.Show("Invalid smoke color");
                return;
            }
        }
    private void m_UpdateDrawingTexture()
    {
        if (string.IsNullOrEmpty(m_Text))
        {
            return;
        }
        System.Drawing.Bitmap bmp = new Bitmap(1, 1);
        using (var graphic = System.Drawing.Graphics.FromImage(bmp))
        {
            var size = graphic.MeasureString(m_Text, defaultFont);
            this.m_MesuredSize = new Vector2(size.Width, size.Height);
        }
        bmp = new Bitmap((int)m_MesuredSize.x, (int)m_MesuredSize.y);

        string colorstr = brushColor.ToString();
        var    syscolor = Color.FromName(colorstr);
        var    brush    = new SolidBrush(syscolor);

        using (var graphic = System.Drawing.Graphics.FromImage(bmp))
        {
            graphic.TextRenderingHint = TextRenderingHint;
            graphic.DrawString(m_Text, defaultFont, brush, PointF.Empty);
            graphic.Flush();
        }
        var ms = new MemoryStream();

        bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
        var pngdat = ms.ToArray();

        var t = new Texture2D(1, 1);

        t.LoadImage(pngdat);
        Img.texture = t;
        Img.SetNativeSize();
    }
Ejemplo n.º 3
0
Archivo: Utils.cs Proyecto: mo5h/omeo
        public static Color ColorFromString(string str)
        {
            Color color = Color.FromName(str);

            if (color.ToArgb() == 0)
            {
                int argb = Int32.Parse(str, NumberStyles.HexNumber);
                color = Color.FromArgb(argb);
            }
            return(color);
        }
Ejemplo n.º 4
0
        public void DrawInServer(int x, int y, string colorString, string taille)
        {
            g = PanelDrawingServer.CreateGraphics();
            Point location = new Point(x, y);

            current = location;
            g.DrawLine(p, old, current);
            old = current;

            CColor clrColor = CColor.FromName(colorString);  // Couleur

            p.Color = clrColor;
            p.Width = float.Parse(taille);

            //  if(Clear == "clear") { PanelDrawingServer.Invalidate(); }
        }
Ejemplo n.º 5
0
        public async Task ColorTask(string input)
        {
            try
            {
                Color result = Color.Empty;

                if (input.StartsWith("#") && input.Length == 7)
                {
                    result = ColorTranslator.FromHtml(input);
                }
                else if (input.StartsWith("#") && input.Length == 9)
                {
                    int argb = int.Parse(input.Replace("#", ""), NumberStyles.HexNumber);
                    result = Color.FromArgb(argb);
                }
                else
                {
                    try
                    {
                        result = Color.FromName(input);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }
                }

                EmbedBuilder builder = new EmbedBuilder();
                builder.WithColor(result);
                builder.Title        = result.Name;
                builder.Description  = string.Empty;
                builder.Description += $"Hex:               #{result.R:X2}{result.G:X2}{result.B:X2}\n";
                builder.Description += $"R {result.R}:G {result.G}:B {result.B}";

                if ($"{result.R:X2}{result.G:X2}{result.B:X2}" != "000000")
                {
                    await this.ReplyAsync(string.Empty, false, builder.Build());
                }
            }
            catch (Exception ex)
            {
                ConsoleHelper.WriteLine(ex);
            }
        }
Ejemplo n.º 6
0
 public Color ColName(EditNull n, IMessage m, string name)
 {
     return(Color.FromName(name));
 }
Ejemplo n.º 7
0
        private void Server_DataReceived(object sender, SimpleTCP.Message e)
        {
            txtStatusServer.Invoke((MethodInvoker) delegate() //  invoquer une zone de texte à partir d'un autre fil
            {
                txtStatusServer.Text += e.MessageString;
                // PanelDrawingServer.
                e.ReplyLine(string.Format("You said :{0}", e.MessageString));

                string phrase  = e.MessageString;
                string[] words = phrase.Split(' ');


                //System.Console.WriteLine("ici c'est : " + words[0] + "  ;  " + words[1] + "  ;  " + words[2]);


                string colorStr = words[3];

                char spearator   = ']';
                String[] strlist = colorStr.ToString().Split(spearator);


                string colorStr2  = strlist[0];
                char spearator2   = '[';
                String[] strlist2 = colorStr2.ToString().Split(spearator2);

                //<<--------

                xCurrent    = int.Parse(words[0]);  //<<--------  Les paramètres à envoyer
                yCurrent    = int.Parse(words[1]);
                xOld        = int.Parse(words[6]);
                yOld        = int.Parse(words[7]);
                colorString = strlist2[1];   //<<--------
                taille      = words[4];      //<<--------

                //   Clear = words[5];

                #region Split Region

                /*       // Taking a string
                 *
                 *     char spearator = ':';
                 *       // Int32 count = 2;
                 *      // using the method
                 *       String[] strlist = e.MessageString.ToString().Split(spearator);
                 *
                 *
                 *       foreach (String s in strlist)
                 *       {
                 *           Console.WriteLine(s);
                 *       }
                 *
                 *      x = int.Parse(strlist[0]);  // Pour avoir que les X
                 *     //int exw = int.Parse(strlist[1]);
                 *     //int t = int.Parse(strlist[1]);
                 *     string st = strlist[1];
                 *     //char separateur = '';
                 *     char separateur = '+';
                 *
                 *     String[] srtlist2 = st.ToString().Split(separateur); //Split pour avoir Y seulement
                 *
                 *     foreach (String ss in srtlist2)
                 *     {
                 *         Console.WriteLine(ss);
                 *     }
                 *          y = int.Parse(srtlist2[0]);
                 *
                 *     char separateurColor = ']';
                 *     String[] srtlistColor = st.ToString().Split(separateurColor); //Split pour avoir Y seulement
                 *     foreach (String colr in srtlistColor)
                 *     {
                 *         Console.WriteLine(colr);
                 *     }
                 *      colorString = srtlistColor[0];
                 *
                 */
                #endregion

                //Console.WriteLine("x=  "+x);
                // Console.WriteLine("y=  "+y);

                //  DrawInServer(x,y,colorString,taille);

                PanelClientClicked = words[5];


                locationCurrent = new Point(xCurrent, yCurrent);
                locationOld     = new Point(xOld, yOld);



                g       = PanelDrawingServer.CreateGraphics();
                current = locationCurrent;
                old     = locationOld;
                g.DrawLine(p, current, old);
                current = old;



                //old = current;

                CColor clrColor = CColor.FromName(colorString);  // Couleur
                p.Color         = clrColor;
                p.Width         = float.Parse(taille);
            });
        }
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            string strValue = value as string;

            if (strValue != null)
            {
                object obj  = null;
                string text = strValue.Trim();

                if (text.Length == 0)
                {
                    obj = Color.Empty;
                }
                else
                {
                    // First, check to see if this is a standard name.
                    //
                    obj = GetNamedColor(text);

                    if (obj == null)
                    {
                        if (culture == null)
                        {
                            culture = CultureInfo.CurrentCulture;
                        }

                        char sep = culture.TextInfo.ListSeparator[0];
                        bool tryMappingToKnownColor = true;

                        TypeConverter intConverter = TypeDescriptor.GetConverter(typeof(int));

                        // If the value is a 6 digit hex number only, then
                        // we want to treat the Alpha as 255, not 0
                        //
                        if (text.IndexOf(sep) == -1)
                        {
                            // text can be '' (empty quoted string)
                            if (text.Length >= 2 && (text[0] == '\'' || text[0] == '"') && text[0] == text[text.Length - 1])
                            {
                                // In quotes means a named value
                                string colorName = text.Substring(1, text.Length - 2);
                                obj = Color.FromName(colorName);
                                tryMappingToKnownColor = false;
                            }
                            else if ((text.Length == 7 && text[0] == '#') ||
                                     (text.Length == 8 && (text.StartsWith("0x") || text.StartsWith("0X"))) ||
                                     (text.Length == 8 && (text.StartsWith("&h") || text.StartsWith("&H"))))
                            {
                                // Note: ConvertFromString will raise exception if value cannot be converted.
                                obj = Color.FromArgb(unchecked ((int)(0xFF000000 | (uint)(int)intConverter.ConvertFromString(context, culture, text))));
                            }
                        }

                        // Nope.  Parse the RGBA from the text.
                        //
                        if (obj == null)
                        {
                            string[] tokens = text.Split(new char[] { sep });
                            int[]    values = new int[tokens.Length];
                            for (int i = 0; i < values.Length; i++)
                            {
                                values[i] = unchecked ((int)intConverter.ConvertFromString(context, culture, tokens[i]));
                            }

                            // We should now have a number of parsed integer values.
                            // We support 1, 3, or 4 arguments:
                            //
                            // 1 -- full ARGB encoded
                            // 3 -- RGB
                            // 4 -- ARGB
                            //
                            switch (values.Length)
                            {
                            case 1:
                                obj = Color.FromArgb(values[0]);
                                break;

                            case 3:
                                obj = Color.FromArgb(values[0], values[1], values[2]);
                                break;

                            case 4:
                                obj = Color.FromArgb(values[0], values[1], values[2], values[3]);
                                break;
                            }
                            tryMappingToKnownColor = true;
                        }

                        if ((obj != null) && tryMappingToKnownColor)
                        {
                            // Now check to see if this color matches one of our known colors.
                            // If it does, then substitute it.  We can only do this for "Colors"
                            // because system colors morph with user settings.
                            //
                            int targetARGB = ((Color)obj).ToArgb();

                            foreach (Color c in Colors.Values)
                            {
                                if (c.ToArgb() == targetARGB)
                                {
                                    obj = c;
                                    break;
                                }
                            }
                        }
                    }

                    if (obj == null)
                    {
                        throw new ArgumentException(SR.GetString(SR.InvalidColor, text));
                    }
                }
                return(obj);
            }
            return(base.ConvertFrom(context, culture, value));
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Convert string into solid brush.
 /// </summary>
 /// <param name="brushColor"></param>
 /// <returns></returns>
 public static SolidBrush ToSolidBrush(this string brushColor)
 {
     return(!string.IsNullOrEmpty(brushColor)
         ? new SolidBrush(Color.FromName(brushColor))
         : null);
 }
        public static Color ConvertFromString(string strValue, CultureInfo culture)
        {
            Debug.Assert(culture != null);

            string text = strValue.Trim();

            if (text.Length == 0)
            {
                return(Color.Empty);
            }

            {
                Color c;
                // First, check to see if this is a standard name.
                //
                if (ColorTable.TryGetNamedColor(text, out c))
                {
                    return(c);
                }
            }

            char sep = culture.TextInfo.ListSeparator[0];

            // If the value is a 6 digit hex number only, then
            // we want to treat the Alpha as 255, not 0
            //
            if (text.IndexOf(sep) == -1)
            {
                // text can be '' (empty quoted string)
                if (text.Length >= 2 && (text[0] == '\'' || text[0] == '"') && text[0] == text[text.Length - 1])
                {
                    // In quotes means a named value
                    string colorName = text.Substring(1, text.Length - 2);
                    return(Color.FromName(colorName));
                }
                else if ((text.Length == 7 && text[0] == '#') ||
                         (text.Length == 8 && (text.StartsWith("0x") || text.StartsWith("0X"))) ||
                         (text.Length == 8 && (text.StartsWith("&h") || text.StartsWith("&H"))))
                {
                    // Note: int.Parse will raise exception if value cannot be converted.
                    return(PossibleKnownColor(Color.FromArgb(unchecked ((int)(0xFF000000 | (uint)IntFromString(text, culture))))));
                }
            }

            // Nope. Parse the RGBA from the text.
            //
            string[] tokens = text.Split(sep);
            int[]    values = new int[tokens.Length];
            for (int i = 0; i < values.Length; i++)
            {
                values[i] = unchecked (IntFromString(tokens[i], culture));
            }

            // We should now have a number of parsed integer values.
            // We support 1, 3, or 4 arguments:
            //
            // 1 -- full ARGB encoded
            // 3 -- RGB
            // 4 -- ARGB
            //
            switch (values.Length)
            {
            case 1:
                return(PossibleKnownColor(Color.FromArgb(values[0])));

            case 3:
                return(PossibleKnownColor(Color.FromArgb(values[0], values[1], values[2])));

            case 4:
                return(PossibleKnownColor(Color.FromArgb(values[0], values[1], values[2], values[3])));
            }

            throw new ArgumentException($"Invalid color: {text}");
        }