Пример #1
0
        private void onDrawComboBoxColorSelectorItem(DrawItemEventArgs e)
        {
            if (e.Index < 0)
            {
                return;
            }

            e.DrawBackground();
            e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            int iconMargin = 5;
            int iconSize   = e.Bounds.Height; // draw square icon
            ColorSelectorComboBoxItem item = (ColorSelectorComboBoxItem)(comboBoxColorSelector.Items[e.Index]);
            Icon icon = getCachedIcon(item.Color);

            if (icon != null)
            {
                Rectangle iconRect = new Rectangle(e.Bounds.X + iconMargin, e.Bounds.Y, iconSize, iconSize);
                e.Graphics.DrawIcon(icon, iconRect);
            }

            int       iconTextMargin = 5;
            Rectangle textRect       = new Rectangle(
                e.Bounds.X + iconMargin + iconSize + iconTextMargin, e.Bounds.Y,
                e.Bounds.Width - iconMargin - iconSize - iconTextMargin, e.Bounds.Height);
            bool  isSelected = (e.State & DrawItemState.Selected) == DrawItemState.Selected;
            Brush textBrush  = isSelected ? SystemBrushes.HighlightText : SystemBrushes.ControlText;

            e.Graphics.DrawString(item.HumanFriendlyName, comboBoxColorSelector.Font, textBrush, textRect);
        }
Пример #2
0
        private void selectComboBoxColor(Color color)
        {
            comboBoxColorSelector.SelectedItem = null;
            ColorSelectorComboBoxItem comboBoxItem = comboBoxColorSelector.Items
                                                     .Cast <ColorSelectorComboBoxItem>()
                                                     .FirstOrDefault(item => item.Color.Equals(color));

            if (comboBoxItem == null)
            {
                Debug.Assert(false);
                Trace.TraceError("[MainForm] Cannot find color {0} in comboBoxColorSelector", color.ToString());
                return;
            }
            comboBoxColorSelector.SelectedItem = comboBoxItem;
        }