private void GradientPanel_MouseDown(object sender, MouseEventArgs e) { if (CurrentGradient == null) { return; } activeGradientColorEntry = GetGradientColorEntryFromLocation(e.X); if (activeGradientColorEntry != null) { if (e.Button == MouseButtons.Left) { // drag draggingGradientColorEntryNow = true; } else if (e.Button == MouseButtons.Right) { // delete CurrentGradient.ColorEntries.Remove(activeGradientColorEntry); } } else { if (e.Button == MouseButtons.Left) { // add double location = GetColorEntryLocationFromX(e.X); Color color = CurrentGradient.GetColor(location); CurrentGradient.ColorEntries.Add(new GradientColorEntry(color, location)); } } DrawGradient(); CopyBackBufferToScreen(); }
private void DrawGradient() { Graphics graphics = Graphics.FromImage(gradientPanelBackBuffer); graphics.Clear(gradientPanel.BackColor); if (CurrentGradient != null) { Gradient.FillCheckerboardRectangle(graphics, gradientRectangle, 8); CurrentGradient.Draw(graphics, gradientRectangle, 0.0, 1.0, Gradient.Direction.Horizontal); graphics.DrawRectangle(Pens.Black, new Rectangle(gradientRectangle.Left - 1, gradientRectangle.Top - 1, gradientRectangle.Width + 2, gradientRectangle.Height + 1)); DrawColorEntryMarkers(); RefreshGradientList(true); } graphics.Dispose(); }