Home > Net >  C # how to cancel the step after drawing
C # how to cancel the step after drawing

Time:10-17

How to write c # how to undo step after drawing code

CodePudding user response:

Mouse press and lift up between all the coordinates of the mouse in an array, the array in a collection, cancel, delete the collection of the last array

CodePudding user response:

Command mode, command mode may be revoked

CodePudding user response:

refer to the original poster qq_36431749 response:
how to write c # how to cancel the step after drawing code oh


Can see drawtool, probably all graphics is stored for each action, when the cancellation is restored to the last movement pattern of the storage

CodePudding user response:

Save every step!

CodePudding user response:

Right, save every step, when you undo the last step popup out of step the stack, and then from start to finish all the painting operation again

CodePudding user response:

Record list of steps, cancel the last step data, drawing ~

CodePudding user response:

reference 4 floor xuzuning response:
save every step!

What can you say something about the specific logic,
1, the copies of the original image and to copy figure drawing, drawing every time save,
2, began to withdraw, will save the drawing steps, the final step to delete,
3, the copies of the original picture again and copy to figure drawing, the steps to save before traverse again,
.
Want to ask next, is this logic?
I now have a similar situation, that is, according to this logic, very card,
Scenario is as follows:
There is a picture, I want to achieve the function district, is in the picture, draw a dashed rectangle,
And I hope that when the mouse moves, real-time refresh selection on the picture size,
At that time, my mouse every move a bit, to copy a piece of artwork, draw a rectangle on the replica,
Move the mouse to dozens of pixels, pictures will copy the dozens,
Although there is a release operation, don't have to worry about memory problems, but the feeling on the drawing board is very card,
Specific code as follows, please give directions:
 private void picboxTotal_MouseMove (object sender, MouseEventArgs e) 
{
//draw a dotted line matrix selected area
If (e.B utton==MouseButtons. Left & amp; & Enclosing picboxTotal Image!=null)
{
//will start and end coordinates restructuring, find out the end of the initial coordinate of the upper left corner and the lower right corner coordinates
Point the startPoint=new Point (Math. Min (downStart. X, e.L ocation. X), Math, Min (downStart. J Y, e.L ocation. Y));
Point the endPoint=new Point (Math. Max (downStart. X, e.L ocation. X), Math. Max (downStart. J Y, e.L ocation. Y));
//selected area size
The Size selectedSize=new Size (Math. Abs (downStart. X-ray e.L ocation. X), Math. Abs (downStart. Y e.L - ocation. Y));

//start coordinates are greater than zero, end coordinates are less than the image size, namely figure within
If (the startPoint. X & gt;=0 & amp; & The startPoint. Y & gt;=0
& & The endPoint. X & lt; Enclosing PicTotalBitmap. Size. Width
& & The endPoint. Y & lt; Enclosing PicTotalBitmap. Size. Height)
{
//move more than 2 pixels
If (selectedSize. Width & gt; 2 & amp; & SelectedSize. Height & gt; 2)
{
//copy a picture, do not pollute the original
Image tempImage=(Image) this. PicTotalBitmap. Clone ();

//create a mapping area
Graphics graphic=Graphics. FromImage (tempImage);
//create a brush, ready to use dotted line in the HuaXuan area
Pen p1=new Pen (Color Black, 1);
P1. DashStyle=System. Drawing. Drawing2D. DashStyle. Dot;
//
the coordinates of the selected areaA Rectangle selectedRect=new Rectangle (the startPoint selectedSize);
Graphic. DrawRectangle (p1, selectedRect);

//display the picture
Enclosing picboxTotal. Image. The Dispose ();
This. PicboxTotal. Image=tempImage;

//release resources
Graphic. The Dispose ();
}
}
}
}

CodePudding user response:

Do figure there are generally two kinds of method:
1, use the list to save every step of the drawing instructions, redrawn, all drawing instruction execution again, this way, you just need to delete list the final instructions,
2, bitmap preservation, redrawn, save the bitmap to be obtained, this, the last saved bitmap delete, use the last saved bitmap,
  •  Tags:  
  • C#
  • Related