示例#1
0
        static string FormatColorInfo(Color color, ColorInfoFormat format, bool ui)
        {
            string infoText = string.Empty;

            if (ui)
            {
                switch (format)
                {
                case ColorInfoFormat.RGB:
                    infoText = $"R: {color.R}\n" +
                               $"G: {color.G}\n" +
                               $"B: {color.B}";
                    break;

                case ColorInfoFormat.CMYK:
                    var cmyk = new CMYK(color);

                    infoText = $"C: {cmyk.C:F3}\n" +
                               $"M: {cmyk.M:F3}\n" +
                               $"Y: {cmyk.Y:F3}\n" +
                               $"K: {cmyk.K:F3}";
                    break;

                case ColorInfoFormat.HEX:
                    infoText += "Hex: " + color.ToHexString();
                    break;

                default:
                    break;
                }
            }
            else
            {
                switch (format)
                {
                case ColorInfoFormat.RGB:
                    infoText = $"{color.R} {color.G} {color.B}";
                    break;

                case ColorInfoFormat.CMYK:
                    var cmyk = new CMYK(color);
                    infoText = $"{cmyk.C:F3} {cmyk.M:F3} {cmyk.Y:F3} {cmyk.K:F3}";
                    break;

                case ColorInfoFormat.HEX:
                    infoText = color.ToHexString();
                    break;

                default:
                    break;
                }
            }

            return(infoText);
        }
示例#2
0
        private void OnFormatChanged(object sender, EventArgs e)
        {
            if (sender is RadioButton)
            {
                if (rgbRadioButton.Checked)
                {
                    _currentInfoFormat = ColorInfoFormat.RGB;
                }
                else if (hexRadioButton.Checked)
                {
                    _currentInfoFormat = ColorInfoFormat.HEX;
                }
                else if (cmykRadioButton.Checked)
                {
                    _currentInfoFormat = ColorInfoFormat.CMYK;
                }

                colorInfoLabel.Text = FormatColorInfo(_currentColor, _currentInfoFormat, true);
            }
        }