public override Object ShowDialog(PropertyItem propertyItem, Object propertyValue, IInputElement commandSource) { HashSet<Color> discreteColors = GetDiscreteColors(propertyItem.Component); Color colorValue; if (propertyValue != null) { colorValue = (Color)propertyValue; } else { colorValue = discreteColors.Any() ? discreteColors.First() : Color.White; } DialogResult result; if (discreteColors.Any()) { using (DiscreteColorPicker dcp = new DiscreteColorPicker()) { dcp.ValidColors = discreteColors; dcp.SingleColorOnly = true; dcp.SelectedColors = new List<Color> {colorValue}; dcp.Text = propertyItem.DisplayName; result = dcp.ShowDialog(); if (result == DialogResult.OK) { propertyValue = !dcp.SelectedColors.Any() ? discreteColors.First() : dcp.SelectedColors.First(); } } } else { using (ColorPicker cp = new ColorPicker()) { cp.LockValue_V = true; cp.Color = XYZ.FromRGB(colorValue); cp.Text = propertyItem.DisplayName; result = cp.ShowDialog(); if (result == DialogResult.OK) { propertyValue = cp.Color.ToRGB().ToArgb(); } } } return propertyValue; }
private void panelColor_Click(object sender, EventArgs e) { if (_discreteColors) { using (DiscreteColorPicker dcp = new DiscreteColorPicker()) { dcp.ValidColors = _validDiscreteColors; dcp.SingleColorOnly = true; dcp.SelectedColors = new List<Color> { Color }; DialogResult result = dcp.ShowDialog(); if (result == DialogResult.OK) { if (dcp.SelectedColors.Count() == 0) { Color = Color.White; } else { RGBColor = dcp.SelectedColors.First(); } } } } else { using (ColorPicker cp = new ColorPicker()) { cp.LockValue_V = false; cp.Color = XYZ.FromRGB(Color); DialogResult result = cp.ShowDialog(); if (result == DialogResult.OK) { RGBColor = cp.Color.ToRGB(); } } } }
// edits the selected color in the 'edit' control private void editSelectedPoints() { if (edit.Gradient == null || edit.FocusSelection) return; if (DiscreteColors) { List<Color> selectedColors = new List<Color>(); foreach (ColorGradient.Point point in edit.Selection) { ColorPoint pt = point as ColorPoint; if (pt == null) continue; selectedColors.Add(pt.Color.ToRGB().ToArgb()); } using (DiscreteColorPicker picker = new DiscreteColorPicker()) { picker.ValidColors = ValidDiscreteColors; picker.SelectedColors = selectedColors; if (picker.ShowDialog() == DialogResult.OK) { if (picker.SelectedColors.Count() == 0) { DeleteColor(); } else if (picker.SelectedColors.Count() == selectedColors.Count) { int i = 0; foreach (Color selectedColor in picker.SelectedColors) { ColorPoint pt = edit.Selection[i] as ColorPoint; pt.Color = XYZ.FromRGB(selectedColor); } } else { double position = edit.Selection.First().Position; foreach (ColorGradient.Point point in edit.Selection) { edit.Gradient.Colors.Remove(point as ColorPoint); } foreach (Color selectedColor in picker.SelectedColors) { ColorPoint newPoint = new ColorPoint(selectedColor, position); edit.Gradient.Colors.Add(newPoint); } } } } } else { if (edit.Selection.Count > 1) MessageBox.Show("Non-discrete color gradient, >1 selected point. oops! please report it."); ColorPoint pt = edit.Selection.FirstOrDefault() as ColorPoint; if (pt == null) return; using (ColorPicker frm = new ColorPicker(_mode, _fader)) { frm.LockValue_V = LockColorEditorHSV_Value; frm.Color = _xyz; if (frm.ShowDialog(this.FindForm()) == DialogResult.OK) { pt.Color = _xyz = frm.Color; lblColorSelect.Color = _xyz.ToRGB().ToArgb(); _mode = frm.SecondaryMode; _fader = frm.PrimaryFader; } } } }
// edits the selected color in the 'edit' control private void editSelectedPoints() { if (edit.Gradient == null || edit.FocusSelection) return; if (DiscreteColors) { List<Color> selectedColors = new List<Color>(); foreach (ColorGradient.Point point in edit.Selection) { ColorPoint pt = point as ColorPoint; if (pt == null) continue; selectedColors.Add(pt.Color.ToRGB().ToArgb()); } using (DiscreteColorPicker picker = new DiscreteColorPicker()) { picker.ValidColors = ValidDiscreteColors; picker.SelectedColors = selectedColors; if (picker.ShowDialog() == DialogResult.OK) { if (picker.SelectedColors.Count() == 0) { DeleteColor(); } else if (picker.SelectedColors.Count() == selectedColors.Count) { int i = 0; foreach (Color selectedColor in picker.SelectedColors) { ColorPoint pt = edit.Selection[i] as ColorPoint; pt.Color = XYZ.FromRGB(selectedColor); } } else { double position = edit.Selection.First().Position; foreach (ColorGradient.Point point in edit.Selection) { edit.Gradient.Colors.Remove(point as ColorPoint); } foreach (Color selectedColor in picker.SelectedColors) { ColorPoint newPoint = new ColorPoint(selectedColor, position); edit.Gradient.Colors.Add(newPoint); } } } } } else { if (edit.Selection.Count > 1) { //messageBox Arguments are (Text, Title, No Button Visible, Cancel Button Visible) MessageBoxForm.msgIcon = SystemIcons.Error; //this is used if you want to add a system icon to the message form. var messageBox = new MessageBoxForm("Non-discrete color gradient, >1 selected point. oops! please report it.", "Delete library gradient?", false, false); messageBox.ShowDialog(); } ColorPoint pt = edit.Selection.FirstOrDefault() as ColorPoint; if (pt == null) return; using (ColorPicker frm = new ColorPicker(_mode, _fader)) { frm.LockValue_V = LockColorEditorHSV_Value; frm.Color = _xyz; if (frm.ShowDialog(this.FindForm()) == DialogResult.OK) { pt.Color = _xyz = frm.Color; lblColorSelect.Color = _xyz.ToRGB().ToArgb(); _mode = frm.SecondaryMode; _fader = frm.PrimaryFader; } } } }