private void lstColors_DoubleClick(object sender, EventArgs e) { ListBox.SelectedIndexCollection indices = lstColors.SelectedIndices; if ((_colorSource == null) || (indices.Count <= 0)) { return; } int count = indices.Count; if (count == 1) { int index = indices[0]; _dlgColor.Color = (Color)(ARGBPixel)lstColors.Items[index]; if (_dlgColor.ShowDialog(this) == DialogResult.OK) { ARGBPixel p = (ARGBPixel)_dlgColor.Color; lstColors.Items[index] = p; _colorSource.SetColor(index, p); } } else { //Sort indices int[] sorted = new int[count]; indices.CopyTo(sorted, 0); Array.Sort(sorted); _dlgGradient.StartColor = (Color)(ARGBPixel)lstColors.Items[sorted[0]]; _dlgGradient.EndColor = (Color)(ARGBPixel)lstColors.Items[sorted[count - 1]]; if (_dlgGradient.ShowDialog(this) == DialogResult.OK) { //Interpolate and apply to each in succession. ARGBPixel start = (ARGBPixel)_dlgGradient.StartColor; ARGBPixel end = (ARGBPixel)_dlgGradient.EndColor; float stepA = (end.A - start.A) / (float)count; float stepR = (end.R - start.R) / (float)count; float stepG = (end.G - start.G) / (float)count; float stepB = (end.B - start.B) / (float)count; for (int i = 0; i < count; i++) { ARGBPixel p = new ARGBPixel( (byte)(start.A + (i * stepA)), (byte)(start.R + (i * stepR)), (byte)(start.G + (i * stepG)), (byte)(start.B + (i * stepB))); lstColors.Items[sorted[i]] = p; _colorSource.SetColor(sorted[i], p); } } } }
private void lstColors_DoubleClick(object sender, EventArgs e) { var indices = SelectedIndices; if ((_colorSource == null) || (indices.Count <= 0)) { return; } int count = indices.Count; if (count == 1) { tempIndex = indices[0]; ARGBPixel prev = (ARGBPixel)lstColors.Items[tempIndex]; _dlgColor.Color = (Color)prev; _dlgColor.OnColorChanged += _dlgColor_OnColorChanged; if (_dlgColor.ShowDialog(this) != DialogResult.OK) { if (tempIndex >= 0) { lstColors.Items[tempIndex] = prev; _colorSource.SetColor(tempIndex, _colorId, prev); if (CurrentColorChanged != null) { CurrentColorChanged(this, EventArgs.Empty); } } } _dlgColor.OnColorChanged -= _dlgColor_OnColorChanged; tempIndex = -1; } else { //Sort indices int[] sorted = new int[count]; indices.CopyTo(sorted, 0); Array.Sort(sorted); _dlgGradient.StartColor = (Color)(ARGBPixel)lstColors.Items[sorted[0]]; _dlgGradient.EndColor = (Color)(ARGBPixel)lstColors.Items[sorted[count - 1]]; if (_dlgGradient.ShowDialog(this) == DialogResult.OK) { //Interpolate and apply to each in succession. ARGBPixel start = (ARGBPixel)_dlgGradient.StartColor; ARGBPixel end = (ARGBPixel)_dlgGradient.EndColor; float stepA = (end.A - start.A) / (float)count; float stepR = (end.R - start.R) / (float)count; float stepG = (end.G - start.G) / (float)count; float stepB = (end.B - start.B) / (float)count; for (int i = 0; i < count; i++) { ARGBPixel p = new ARGBPixel( (byte)(start.A + (i * stepA)), (byte)(start.R + (i * stepR)), (byte)(start.G + (i * stepG)), (byte)(start.B + (i * stepB))); lstColors.Items[sorted[i]] = p; _colorSource.SetColor(sorted[i], _colorId, p); } } } }