/// <summary> /// Ctrl + Left Mouse => Coppy my Rectangle /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void myrect_MouseDown(object sender, MouseEventArgs e) { _mousePoint = e.Location; if (e.Button == MouseButtons.Left && ((ModifierKeys & Keys.Control) == Keys.Control)) { try { Shapes.MyRectangle newRect = new Shapes.MyRectangle(); newRect.Location = saveRect.Location; newRect.Size = new Size(saveRect.Width, saveRect.Height); newRect.Cursor = Cursors.Cross; newRect.MouseDown += new MouseEventHandler(myrect_MouseDown); newRect.MouseMove += new MouseEventHandler(myrect_MouseMove); newRect.Click += new EventHandler(myrect_clicked); newRect.MouseHover += new EventHandler(myrect_MouseHover); saveRect = newRect; this.Controls.Add(newRect); } catch (Exception ex) { throw new Exception(ex.Message); } } }
/// <summary> /// Selected my Rectangle (focus) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void myrect_clicked(object sender, EventArgs e) { if (Control.ModifierKeys != Keys.Control) { saveRect = (sender as Shapes.MyRectangle); } }
void myrect_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { Shapes.MyRectangle myRect = (sender as Shapes.MyRectangle); // Moving my shape Point mousePos = GridDesigner.ActiveForm.PointToClient(Cursor.Position); mousePos.Offset(-_mousePoint.X, -_mousePoint.Y); myRect.Location = mousePos; // Destroy my shape if (myRect.Top < txt_horizontal_ruler.Size.Height - 15 || myRect.Left < txt_vertical_ruler.Size.Width - 15) { this.Controls.Remove(myRect); myRect.Dispose(); } } }
private void GridDesigner_MouseUp(object sender, MouseEventArgs e) { if (e.Button != MouseButtons.Right) { return; } if (!_onDrawing) { return; } try { Point tempEndPoint = e.Location; var point1 = new Point( Math.Max(0, Math.Min(_mousePoint.X, tempEndPoint.X)), Math.Max(0, Math.Min(_mousePoint.Y, tempEndPoint.Y))); var point2 = new Point( Math.Min(this.Width, Math.Max(_mousePoint.X, tempEndPoint.X)), Math.Min(this.Height, Math.Max(_mousePoint.Y, tempEndPoint.Y))); Shapes.MyRectangle m = new Shapes.MyRectangle(); m.Location = point1; m.Size = new Size(point2.X - point1.X, point2.Y - point1.Y); m.Cursor = Cursors.Cross; m.MouseDown += new MouseEventHandler(myrect_MouseDown); m.MouseMove += new MouseEventHandler(myrect_MouseMove); m.Click += new EventHandler(myrect_clicked); m.MouseHover += new EventHandler(myrect_MouseHover); saveRect = m; _onDrawing = false; this.Controls.Add(m); } catch (Exception ex) { throw new Exception(ex.Message); } }
/// <summary> /// Drawing Tooltip on my Rectangle hover /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void myrect_MouseHover(object sender, EventArgs e) { Shapes.MyRectangle myRect = (sender as Shapes.MyRectangle); tlp.SetToolTip(myRect, myRect.Width + ", " + myRect.Height); }