/// <summary> /// Raises the Click event with the specified color /// </summary> /// <param name="color">Color to pass to Click event handlers</param> protected void RaiseClickEvent(Color color) { if (Click != null) { ColorPickerEventArgs args = new ColorPickerEventArgs(); args.Value = color; Click(this, args); } }
/// <summary> /// Updates the selected palette item. /// </summary> /// <param name="index">New palette index</param> /// <param name="scrollIntoView">Control will be scrolled so /// that new item is fully visible when true</param> protected void SetSelected(int index, bool scrollIntoView) { // Something to do only if item has changed if (index != _selected) { // Get update region if (_selected >= 0) { Invalidate(IndexToRectangle(_selected)); } if (index >= 0) { Rectangle rect = IndexToRectangle(index); Invalidate(rect); // Scroll if needed if (_autoScroll && scrollIntoView) { if (rect.Top < 0) { // Scroll up Point point = new Point(0, -AutoScrollPosition.Y); point.Y += (rect.Top - Margins); AutoScrollPosition = point; } else if (rect.Bottom >= ClientRectangle.Bottom) { // Scroll down Point point = new Point(0, -AutoScrollPosition.Y); point.Y += ((rect.Bottom - ClientRectangle.Bottom) + Margins); AutoScrollPosition = point; } } } // Update selected index _selected = index; // Raise SelectionChanged event if (SelectionChanged != null && _selected >= 0) { ColorPickerEventArgs args = new ColorPickerEventArgs(); args.Value = ColorItems[_selected]; SelectionChanged(this, args); } } }