private void TheImage_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { PreviewHue(e.X, e.Y); if (e.Button == MouseButtons.Left) { // If Alt is pressed, don't select if (AltPressed()) { return; } // Get the hue index ( zero based ) int column = (int)(e.X / 9); int row = (int)(e.Y / 5); int selHue = (int)(column * 60 + row + 1); if ((column >= 0) && (column <= 49) && (row >= 0) && (row <= 59)) { if (!SelectedHues.Contains(selHue)) { SelectedHues.Add(selHue); PreviousSelectedColor = selHue; DrawSelectionChart(); } } } }
private void TheImage_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { // Get the hue index ( zero based ) SelectedColor = GetHueIndex(e.X, e.Y); // Handle selection of hues if (!(ShiftPressed() || ControlPressed())) { if ((SelectedHues.Count == 1) && (SelectedHues.Contains(SelectedColor))) { SelectedHues.Clear(); DrawSelectionChart(); return; } // No modifier keys pressed. Clear selection and add current item SelectedHues.Clear(); SelectedHues.Add(SelectedColor); PreviousSelectedColor = SelectedColor; DrawSelectionChart(); return; } if (SelectedHues.Contains(SelectedColor)) { // Clicking the same just deselects it SelectedHues.Remove(SelectedColor); if (ShiftPressed()) { // Go down if (SelectedHues.Contains((SelectedColor + 1))) { for (int i = (SelectedColor + 1); i <= PreviousSelectedColor; i++) { if (SelectedHues.Contains(i)) { SelectedHues.Remove(i); } else { break; } } } } PreviousSelectedColor = (SelectedColor - 1); DrawSelectionChart(); return; } if (ControlPressed()) { // Add a single item to the list SelectedHues.Add(SelectedColor); PreviousSelectedColor = SelectedColor; DrawSelectionChart(); return; } if (ShiftPressed()) { // Add a selection of items if (PreviousSelectedColor < SelectedColor) { // Moving backwards for (int i = SelectedColor; i > PreviousSelectedColor; i--) { if (!SelectedHues.Contains(i)) { SelectedHues.Add(i); } } } if (PreviousSelectedColor > SelectedColor) { // Moving forward for (int i = SelectedColor; i < PreviousSelectedColor; i++) { if (!SelectedHues.Contains(i)) // Avoid duplicates { SelectedHues.Add(i); } } } PreviousSelectedColor = SelectedColor; DrawSelectionChart(); return; } }