private void cbColor_SelectionChangeCommitted(object sender, EventArgs e) { var cb = (ComboBox)sender; _stroke.Color = DrawUtils.ColorFromIndex(cb.SelectedIndex); pbPreview.Refresh(); }
public static void colorComboSelectedIndexChanged(object sender, ref int LastColorIndex, ChangeCommitted changed) { ComboBox cbox = (ComboBox)sender; if (cbox.SelectedIndex == cbox.Items.Count - 1) { try { int selIndex; using (ColorDialog dlgSelectColor = new ColorDialog()) { dlgSelectColor.Color = DrawUtils.ColorFromIndex(LastColorIndex); selIndex = LastColorIndex; if (dlgSelectColor.ShowDialog() == DialogResult.OK) { Color selColor = dlgSelectColor.Color; if (!DrawUtils.FindColor(selColor)) { DrawUtils.AddCustomColor(selColor); dlgSelectColor.CustomColors = DrawUtils.GetCustomColors(); cbox.Items.Insert(cbox.Items.Count - 1, "Мой цвет"); cbox.SelectedIndex = cbox.Items.Count - 2; } else { cbox.SelectedIndex = DrawUtils.ColorToIndex(selColor); } if (changed != null) { changed(sender, new EventArgs()); } } else { cbox.SelectedIndex = selIndex; } } } catch { } } else { LastColorIndex = cbox.SelectedIndex; cbox.Refresh(); } }
public static void colorComboDrawItem(object sender, DrawItemEventArgs e) { ComboBox cb = (ComboBox)sender; Graphics g = e.Graphics; Color brushColor = DrawUtils.ColorFromIndex(e.Index); // Draw the background of the item. e.DrawBackground(); Rectangle largerect = new Rectangle(e.Bounds.X, e.Bounds.Top, e.Bounds.Width - 1, e.Bounds.Height - 1); Rectangle colorrect = new Rectangle(4, e.Bounds.Top + 2, e.Bounds.Height - 2, e.Bounds.Height - 5); // отрисовка рамки цвета пунктов основных цветов if (DrawUtils.IsNamedColorIndex(e.Index)) { using (SolidBrush brush = new SolidBrush(brushColor)) g.FillRectangle(brush, colorrect); g.DrawRectangle(Pens.Black, colorrect); } RectangleF textRect = new RectangleF(e.Bounds.X + colorrect.Width + 5, e.Bounds.Y + 1, e.Bounds.Width, e.Bounds.Height); using (SolidBrush textColor = new SolidBrush(e.ForeColor)) { if (DrawUtils.IsNamedColorIndex(e.Index)) { // отрисовка пунктов основных цветов g.DrawString(DrawUtils.GetColorNameFromIndex(e.Index), cb.Font, textColor, textRect); } else // отрисовка пунктов дополнительных цветов if (DrawUtils.IsCustomColorIndex(e.Index)) { using (SolidBrush brush = new SolidBrush(brushColor)) g.FillRectangle(brush, largerect); using (Pen pen = new Pen(cb.BackColor)) g.DrawRectangle(pen, largerect); } else // отрисовка последнего пункта: Выбор цвета... { g.DrawString(cb.Items[e.Index].ToString(), cb.Font, textColor, largerect); } } // Draw the focus rectangle if the mouse hovers over an item. e.DrawFocusRectangle(); }
private void cbColor_SelectedIndexChanged(object sender, EventArgs e) { var cbox = (ComboBox)sender; if (cbox.SelectedIndex == cbox.Items.Count - 1) { try { dlgSelectColor.Color = DrawUtils.ColorFromIndex(_lastColorIndex); var selIndex = _lastColorIndex; if (dlgSelectColor.ShowDialog() == DialogResult.OK) { Color selColor = dlgSelectColor.Color; _stroke.Color = selColor; if (!DrawUtils.FindColor(selColor)) { DrawUtils.AddCustomColor(selColor); dlgSelectColor.CustomColors = DrawUtils.GetCustomColors(); cbColor.Items.Insert(cbColor.Items.Count - 1, "Мой цвет"); cbColor.SelectedIndex = cbColor.Items.Count - 2; } else { cbox.SelectedIndex = DrawUtils.ColorToIndex(selColor); } } else { cbox.SelectedIndex = selIndex; } } catch { } } else { _lastColorIndex = cbox.SelectedIndex; cbox.Refresh(); pbPreview.Refresh(); } }
public static Color colorComboSelectionChangeCommitted(object sender) { ComboBox cbox = (ComboBox)sender; return(DrawUtils.ColorFromIndex(cbox.SelectedIndex)); }