Пример #1
0
        private void AddCustomColor(ComboBox box, Color color)
        {
            int argb = color.ToArgb();

            int          i     = 0;
            bool         found = false;
            DisplayColor displayColor;

            while ((i < box.Items.Count) && !found)
            {
                displayColor = (DisplayColor)box.Items[i];
                if (!(found = (displayColor.Color.ToArgb() == argb)))
                {
                    i++;
                }
            }

            if (!found)
            {
                string customName = translator.GetString("CustomColorName");
                if (box.Items[box.Items.Count - 1].ToString().Equals(customName))
                {
                    ((DisplayColor)box.Items[box.Items.Count - 1]).Color = color;
                }
                else
                {
                    displayColor = new DisplayColor(customName, color);
                    box.Items.Add(displayColor);
                }
                i = box.Items.Count - 1;
            }

            box.SelectedIndex = i;
        }
Пример #2
0
        //========================================================================================
        // DrawColorComboItem()
        //========================================================================================

        private void DrawColorComboItem(object sender, DrawItemEventArgs e)
        {
            if (e.Index < 0)
            {
                return;
            }

            ComboBox     box          = (ComboBox)sender;
            DisplayColor displayColor = (DisplayColor)box.Items[e.Index];

            e.DrawBackground();

            bool flag1 = (e.State & DrawItemState.Disabled) != DrawItemState.None;
            bool flag2 = ((e.State & DrawItemState.Focus) != DrawItemState.None) && ((e.State & DrawItemState.NoFocusRect) == DrawItemState.None);
            bool flag3 = (e.State & DrawItemState.Selected) != DrawItemState.None;

            if (flag2)
            {
                e.DrawFocusRectangle();
            }

            Brush brush1 = new SolidBrush(displayColor.Color);

            try
            {
                Rectangle rectangle1;
                Rectangle rectangle2;
                rectangle1 = new Rectangle(e.Bounds.Left, e.Bounds.Top, Math.Min(e.Bounds.Width, 0x1c), e.Bounds.Height);
                rectangle1.Inflate(-2, -2);
                rectangle2 = new Rectangle(rectangle1.Right + 1, e.Bounds.Top, (e.Bounds.Width - rectangle1.Right) - 1, e.Bounds.Height);
                if (e.State == DrawItemState.HotLight)
                {
                    e.Graphics.FillRectangle(SystemBrushes.Highlight, e.Bounds);
                }
                e.Graphics.FillRectangle(brush1, rectangle1);
                e.Graphics.DrawRectangle(Pens.Black, rectangle1);
                Brush brush2 = new SolidBrush(e.ForeColor);
                if (flag1)
                {
                    brush2 = Brushes.Gray;
                }
                else if (flag3)
                {
                    brush2 = SystemBrushes.HighlightText;
                }
                e.Graphics.DrawString(displayColor.Name, this.Font, brush2, (RectangleF)rectangle2);
            }
            finally
            {
                brush1.Dispose();
            }
        }