public void TryParseRGB_255_255_25()
        {
            //arrange
            int    red   = 255;
            int    green = 255;
            int    blue  = 25;
            string text  = String.Format("{0},{1},{2}", red, green, blue);
            Color  color = Color.Black;

            //act
            ConvertColors.TryParseRGB(text, out color);
            //assert
            Assert.AreEqual(red, color.R);
            Assert.AreEqual(green, color.G);
            Assert.AreEqual(blue, color.B);
        }
示例#2
0
        private void OnTextChanged(object sender, EventArgs e)
        {
            TextBox textBox  = sender as TextBox;
            Color   newColor = System.Drawing.Color.Black;
            bool    success  = false;

            switch (textBox.Name)
            {
            case NAME_HEXADECIMAL:
                if ((textBox.Text.Length == 6 && !textBox.Text.StartsWith("#")) || (textBox.Text.Length == 7 && textBox.Text.StartsWith("#")))
                {
                    success = ConvertColors.TryParseHexadecimal(textBox.Text, out newColor);
                }
                break;

            case NAME_RGB:
                if (textBox.Text.EndsWith(")"))
                {
                    success = ConvertColors.TryParseRGB(textBox.Text, out newColor);
                }
                break;

            case NAME_HSV:
                if (textBox.Text.EndsWith(")"))
                {
                    success = ConvertColors.TryParseHSV(textBox.Text, out newColor);
                }
                break;
            }
            if (success)
            {
                Color = newColor;
                if (ColorChanged != null)
                {
                    ColorChanged(this, new ColorEventArgs(newColor));
                }
            }
            else
            {
                textBox.BackColor = COLOR_ERROR;
            }
        }