public FillProps(Fill fill) { InitializeComponent(); // ------------------------------------------------------------------- cbColor.Items.Clear(); cbColor.Items.AddRange(DrawUtils.GetAllColorNames()); // получение всех имён доступных цветов cbColor.Items.Add("Выбор цвета..."); // добавление пункта выбора цвета cbColor.Text = DrawUtils.GetColorNameFromIndex(_lastColorIndex); // ------------------------------------------------------------------- _fill = (Fill)fill.Clone(); // ------------------------------- var index = DrawUtils.ColorToIndex(fill.Color); if (index < 0) { DrawUtils.AddCustomColor(fill.Color); cbColor.Items.Insert(cbColor.Items.Count - 1, "Мой цвет"); index = cbColor.Items.Count - 2; } if (index >= 0) { cbColor.SelectedIndex = index; } // ------------------------------- tbTrasparent.Value = 255 - fill.Alpha; lbTrasparent.Text = String.Format(CultureInfo.InvariantCulture, "{0}", (int)(tbTrasparent.Value / 255.0 * 100.0)) + @" %"; }
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) { var selColor = dlgSelectColor.Color; _fill.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(); } }