I want to move my newly drawn rectangles from x direction to X++ , or y to Y++ , and while moving by button event , old rectangle should be deleted and new one should appear .
{ // listRec has 9 rectangles and this is button click event . Rectangle[] recn = listRec.ToArray(); for (int i = 0; i < 9; i++) { Rectangle newrec = new System.Drawing.Rectangle(); newrec.X = recn[i].X + j; newrec.Y = recn[i].Y; newrec.Width = recn[i].Width; newrec.Height = recn[i].Height; Rectangle rect = new Rectangle(newrec.X, newrec.Y,newrec.Width, newrec.Height)); g.DrawRectangle(Pens.Red, rect); pictureBox1.Refresh(); //ra[0].Location.X = newrec(ra[0].X+10,ra[0].Y,ra[0].Width,ra[0].Height); } pictureBox1.Invalidate(); this.Invalidate(); j = j + 10; pictureBox1.Refresh(); }
Maen BadwanPosted Jun 1, 2017, 4:30 PM
https://stackoverflow.com/questions/4060446/how-to-draw-rectangle-on-mousedown-move-c-sharp
https://stackoverflow.com/questions/32600523/how-do-i-move-a-graphics-rectangle-with-my-keys
https://stackoverflow.com/questions/15981840/how-to-draw-and-move-shapes-using-mouse-in-c-sharp
In general, if you are looking for creating markup (annotations) objects, you can try the Annotations features from LEADTOOLS. They provide high-level .NET classes that can help you to create different types of shapes (rectangle, ellipse, text, note, point, etc.) with full control over them (move, delete, show, hide, etc.). You can check the .NET ClickOnce Annotations demo here:
https://www.leadtools.com/demos/click-once/annotations