Note that there are some explanatory texts on larger screens.

plurals
  1. PORectangle can't be drawn on the panel by mouse dragging runtime
    text
    copied!<p>I am trying to draw a rectangle on a panel, but nothing is drawn. Below is the code to show how I draw a rectangle on the panel. In my code <code>SetSelectionRect()</code> is used to set the rectangle to be drawn. For these I use following methods.</p> <pre><code> private void Panel_MouseDown(object sender, MouseEventArgs e) { Point point = new Point(); this.mouseDown = true; this.Panel.SendToBack(); point = this.Panel.PointToClient(Cursor.Position); point.X = e.X; point.Y = e.Y; this.selectionStart.X = point.X; this.selectionStart.Y = point.Y; } private void Panel_MouseMove(object sender, MouseEventArgs e) { if (!this.mouseDown) { return; } else { this.mouseMove = true; Point point = this.Panel.PointToClient(Cursor.Position); point.X = e.X; point.Y = e.Y; this.selectionEnd.X = point.X; this.selectionEnd.Y = point.Y; this.SetSelectionRect(); ////this.Panel.Invalidate(); ////this.Invalidate(); } } private void Panel_MouseUp(object sender, MouseEventArgs e) { SetSelectionRect(); this.GetSelectedControls(); this.mouseDown = false; this.mouseMove = false; ////this.Panel.Invalidate(); ////this.Invalidate(); this.Panel.Refresh(); } private void Panel_Paint(object sender, PaintEventArgs e) { ////base.OnPaint(e); drawRect = true when RectangleToolStripMenuItem is Clicked. if (this.drawRect) { using (Pen pen = new Pen(Color.Black, 1F)) { this.rectangle = new RectangleShape(); this.Panel.SendToBack(); this.shapeContainer1.Shapes.Add(this.rectangle); this.rectangle.Location = this.selection.Location; this.rectangle.Size = this.selection.Size; this.rectangle.Name = "rectShape"; this.shapeContainer1.Size = this.Panel.Size; this.shapeContainer1.Location = this.Panel.Location; this.rectangle.Enabled = false; this.rectangle.MouseClick += new MouseEventHandler(this.mouseclick); this.rectangle.MouseMove += new MouseEventHandler(this.mouseMove); this.rectangle.MouseDown += new MouseEventHandler(this.mouseDown); this.rectangle.MouseUp += new MouseEventHandler(this.mouseUp); this.drawRect = false; } } } protected override void OnPaint (PaintEventArgs e) { base.OnPaint(e); } </code></pre> <p>What's wrong with the code?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload