protected override void OnMouseUp(MouseEventArgs e) { if (Capture && e.Button == MouseButtons.Left) { // If the mouse is captured and it's the Left button being released, the user is // done creating a new Ellipse. // Stop capturing the mouse. Capture = false; // Final update of the Ellipse under construction UpdateEllipseUnderConstruction(e.Location); // Add the new Ellipse to our list unless its width or height are zero which would result in a non-visible ellipse if (ellipseConstruction.Ellipse.Rectangle.Width > 0 && ellipseConstruction.Ellipse.Rectangle.Height > 0) { ellipses.Add(ellipseConstruction.Ellipse); } // Since we are done constructing a new Ellipse, we don't need the construction object ellipseConstruction = null; } base.OnMouseUp(e); }
protected override void OnKeyDown(KeyEventArgs e) { // Allow Ellipse creation to be cancelled with the Escape key if (Capture && e.KeyData == Keys.Escape) { Capture = false; // End mouse capture ellipseConstruction = null; // Remove construction ellipse Invalidate(); // Notify operating system that we need to be repainted. } base.OnKeyDown(e); }
protected override void OnMouseDown(MouseEventArgs e) { if (e.Button == MouseButtons.Left) { // Capture mouse until button up. Capture = true; // Create a new Ellipse object and record the [X, Y] origin of this click ellipseConstruction = new EllipseConstruction { Origin = e.Location, Ellipse = new Ellipse { Color = EllipseColors[Rand.Next(EllipseColors.Length)], PenWidth = Rand.Next(1, 6) }, }; } base.OnMouseDown(e); }