示例#1
0
 protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds,
                               System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value,
                               object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle
                               advancedBorderStyle, DataGridViewPaintParts paintParts)
 {
     base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value,
                formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
     graphics.FillRectangle(Brushes.White, cellBounds.X + 1, cellBounds.Y + 1, cellBounds.Width - 2, cellBounds.Height - 2);
     if (this.Value != null && this.Value.ToString() != String.Empty)
     {
         int textLocationX = cellBounds.X + 28;
         int textLocationY = cellBounds.Y + 4;
         graphics.DrawString(this.Value.ToString().Split('.')[1],
                             cellStyle.Font, Brushes.Black, new Point(textLocationX, textLocationY));
         Color    color             = ColorRepresentationHelper.GetColorByValue(this.Value.ToString());
         Graphics showColorGraphics = Graphics.FromImage(showColorBitmap);
         showColorGraphics.Clear(color);
         showColorGraphics.DrawRectangle(Pens.Black, 0, 0, this.showColorBitmap.Width - 1, this.showColorBitmap.Height - 1);
         graphics.DrawImage(this.showColorBitmap, cellBounds.X + 2, cellBounds.Y + 2);
     }
 }
示例#2
0
        private void SetupAllColorRepresentations()
        {
            _allColorRepresentations.Add(
                new ColorFormatModel()
            {
                FormatName = ColorRepresentationType.HEX.ToString(),
#pragma warning disable CA1304 // Specify CultureInfo
                Convert = (Color color) => { return(ColorRepresentationHelper.GetStringRepresentationFromMediaColor(color, ColorRepresentationType.HEX).ToLower()); },
#pragma warning restore CA1304 // Specify CultureInfo
            });

            _allColorRepresentations.Add(
                new ColorFormatModel()
            {
                FormatName = ColorRepresentationType.RGB.ToString(),
                Convert    = (Color color) => { return(ColorRepresentationHelper.GetStringRepresentationFromMediaColor(color, ColorRepresentationType.RGB)); },
            });

            _allColorRepresentations.Add(
                new ColorFormatModel()
            {
                FormatName = ColorRepresentationType.HSL.ToString(),
                Convert    = (Color color) => { return(ColorRepresentationHelper.GetStringRepresentationFromMediaColor(color, ColorRepresentationType.HSL)); },
            });

            _allColorRepresentations.Add(
                new ColorFormatModel()
            {
                FormatName = ColorRepresentationType.HSV.ToString(),
                Convert    = (Color color) => { return(ColorRepresentationHelper.GetStringRepresentationFromMediaColor(color, ColorRepresentationType.HSV)); },
            });

            _allColorRepresentations.Add(
                new ColorFormatModel()
            {
                FormatName = ColorRepresentationType.CMYK.ToString(),
                Convert    = (Color color) => { return(ColorRepresentationHelper.GetStringRepresentationFromMediaColor(color, ColorRepresentationType.CMYK)); },
            });
            _allColorRepresentations.Add(
                new ColorFormatModel()
            {
                FormatName = ColorRepresentationType.HSB.ToString(),
                Convert    = (Color color) => { return(ColorRepresentationHelper.GetStringRepresentationFromMediaColor(color, ColorRepresentationType.HSB)); },
            });
            _allColorRepresentations.Add(
                new ColorFormatModel()
            {
                FormatName = ColorRepresentationType.HSI.ToString(),
                Convert    = (Color color) => { return(ColorRepresentationHelper.GetStringRepresentationFromMediaColor(color, ColorRepresentationType.HSI)); },
            });
            _allColorRepresentations.Add(
                new ColorFormatModel()
            {
                FormatName = ColorRepresentationType.HWB.ToString(),
                Convert    = (Color color) => { return(ColorRepresentationHelper.GetStringRepresentationFromMediaColor(color, ColorRepresentationType.HWB)); },
            });
            _allColorRepresentations.Add(
                new ColorFormatModel()
            {
                FormatName = ColorRepresentationType.NCol.ToString(),
                Convert    = (Color color) => { return(ColorRepresentationHelper.GetStringRepresentationFromMediaColor(color, ColorRepresentationType.NCol)); },
            });
            _allColorRepresentations.Add(
                new ColorFormatModel()
            {
                FormatName = ColorRepresentationType.CIELAB.ToString(),
                Convert    = (Color color) => { return(ColorRepresentationHelper.GetStringRepresentationFromMediaColor(color, ColorRepresentationType.CIELAB)); },
            });
            _allColorRepresentations.Add(
                new ColorFormatModel()
            {
                FormatName = ColorRepresentationType.CIEXYZ.ToString(),
                Convert    = (Color color) => { return(ColorRepresentationHelper.GetStringRepresentationFromMediaColor(color, ColorRepresentationType.CIEXYZ)); },
            });

            _userSettings.VisibleColorFormats.CollectionChanged += VisibleColorFormats_CollectionChanged;

            // Any other custom format to be added here as well that are read from settings
        }
        private void SetupAllColorRepresentations()
        {
            _allColorRepresentations.Add(
                new ColorFormatModel()
            {
                FormatName = ColorRepresentationType.HEX.ToString(),
                Convert    = (Color color) => { return(ColorRepresentationHelper.GetStringRepresentationFromMediaColor(color, ColorRepresentationType.HEX)); },
            });

            _allColorRepresentations.Add(
                new ColorFormatModel()
            {
                FormatName = ColorRepresentationType.RGB.ToString(),
                Convert    = (Color color) => { return(ColorRepresentationHelper.GetStringRepresentationFromMediaColor(color, ColorRepresentationType.RGB)); },
            });

            _allColorRepresentations.Add(
                new ColorFormatModel()
            {
                FormatName = ColorRepresentationType.HSL.ToString(),
                Convert    = (Color color) => { return(ColorRepresentationHelper.GetStringRepresentationFromMediaColor(color, ColorRepresentationType.HSL)); },
            });

            _allColorRepresentations.Add(
                new ColorFormatModel()
            {
                FormatName = ColorRepresentationType.HSV.ToString(),
                Convert    = (Color color) => { return(ColorRepresentationHelper.GetStringRepresentationFromMediaColor(color, ColorRepresentationType.HSV)); },
            });

            _allColorRepresentations.Add(
                new ColorFormatModel()
            {
                FormatName = ColorRepresentationType.CMYK.ToString(),
                Convert    = (Color color) => { return(ColorRepresentationHelper.GetStringRepresentationFromMediaColor(color, ColorRepresentationType.CMYK)); },
            });
            _allColorRepresentations.Add(
                new ColorFormatModel()
            {
                FormatName = ColorRepresentationType.HSB.ToString(),
                Convert    = (Color color) => { return(ColorRepresentationHelper.GetStringRepresentationFromMediaColor(color, ColorRepresentationType.HSB)); },
            });
            _allColorRepresentations.Add(
                new ColorFormatModel()
            {
                FormatName = ColorRepresentationType.HSI.ToString(),
                Convert    = (Color color) => { return(ColorRepresentationHelper.GetStringRepresentationFromMediaColor(color, ColorRepresentationType.HSI)); },
            });
            _allColorRepresentations.Add(
                new ColorFormatModel()
            {
                FormatName = ColorRepresentationType.HWB.ToString(),
                Convert    = (Color color) => { return(ColorRepresentationHelper.GetStringRepresentationFromMediaColor(color, ColorRepresentationType.HWB)); },
            });
            _allColorRepresentations.Add(
                new ColorFormatModel()
            {
                FormatName = ColorRepresentationType.NCol.ToString(),
                Convert    = (Color color) => { return(ColorRepresentationHelper.GetStringRepresentationFromMediaColor(color, ColorRepresentationType.NCol)); },
            });

            _userSettings.VisibleColorFormats.CollectionChanged += VisibleColorFormats_CollectionChanged;

            // Any other custom format to be added here as well that are read from settings
        }
        public void GetStringRepresentationTest(ColorRepresentationType type, string expected)
        {
            var result = ColorRepresentationHelper.GetStringRepresentation(Color.Black, type);

            Assert.AreEqual(result, expected);
        }