protected override void OnDrawItem(DrawItemEventArgs e) { if (this.Items.Count > 0) { ColorListBoxItem item = (ColorListBoxItem)this.Items[e.Index]; item.DrawItem(e, Font, ForeColor, ItemHeight); } }
private void MouseDoubleClick_Action(object sender, MouseEventArgs e) { if (sender == colorListBox1) { ColorListBoxItem item = (ColorListBoxItem)colorListBox1.SelectedItem; SelectedColor = item.Color; } else if (sender == colorListBox2) { ColorListBoxItem item = (ColorListBoxItem)colorListBox2.SelectedItem; SelectedColor = item.Color; } else { SelectedColor = colorPanel1.SelectedColor; } }
public ColorChooser() { InitializeComponent(); foreach (PropertyInfo prop in typeof(SystemColors).GetProperties()) { ColorListBoxItem item = new ColorListBoxItem(); if (prop.PropertyType.FullName == "System.Drawing.Color") { item.Color = Color.FromName(prop.Name); colorListBox1.Items.Add(item); } } var webColors = Enum.GetValues(typeof(KnownColor)) .Cast <KnownColor>() .Where(k => k >= KnownColor.Transparent && k < KnownColor.ButtonFace) //Exclude system colors .Select(k => Color.FromKnownColor(k)) .OrderBy(c => c.GetHue()) .ThenBy(c => c.GetSaturation()) .ThenBy(c => c.GetBrightness()); List <Color> colors = webColors.ToList(); colors.Remove(Color.Transparent); colors.Remove(Color.Black); colors.Remove(Color.White); colors.Insert(0, Color.Transparent); colors.Insert(1, Color.Black); colors.Insert(2, Color.White); foreach (Color c in colors) { ColorListBoxItem item = new ColorListBoxItem(); item.Color = c; colorListBox2.Items.Add(item); } colorPanel1.SelectedColorChanged += ColorPanel1_SelectedColorChanged; }