public SelectedIndexEnumerator(ListBox.SelectedIndexCollection items) { this.items = items; this.current = -1; }
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 button5_Click(object sender, EventArgs e) { ListBox.SelectedIndexCollection col = new ListBox.SelectedIndexCollection(listBox1); ListBox.SelectedObjectCollection col2 = new ListBox.SelectedObjectCollection(listBox1); col = listBox1.SelectedIndices; col2 = listBox1.SelectedItems; string s = ""; foreach (object obj in col2) { s += obj.ToString(); } if (col.Count == 2 && !s.Contains(" E ")) { listBox1.Items.Insert(col[0], col2[0].ToString() + " E " + col2[1].ToString()); listBox1.Items.RemoveAt(col[0]); listBox1.Items.RemoveAt(col[0]); } else { MessageBox.Show("Seleccione dois Filtros Únicos!"); } listBox1.ClearSelected(); }