Demo
Using system; using system. collections. generic; using system. componentmodel; using system. data; using system. drawing; using system. text; using system. windows. forms; using system. drawing. imaging; namespace image {public partial class form1: FORM {bool isdrag = false; rectangle therectangle = new rectangle (new point (0, 0), new size (0, 0 )); point startpoint, oldpoint; private graphics ig; Public form1 () {init Ializecomponent ();} private void button1_click (Object sender, eventargs e) {} private void button2_click (Object sender, eventargs e) {openfiledialog1.filter = "*. JPG ,*. JPEG ,*. BMP ,*. GIF ,*. ICO ,*. PNG ,*. TIF ,*. WMF | *. JPG ;*. JPEG ;*. BMP ;*. GIF ;*. ICO ;*. PNG ;*. TIF ;*. WMF "; openfiledialog1.showdialog (); image myimage = system. drawing. image. fromfile (openfiledialog1.filename); picturebox1.image = myimage;} PRI Vate void picturebox#mousedown (Object sender, mouseeventargs e) {If (E. Button = mousebuttons. Left) {// If painting starts, record the mouse position if (isdrag =! Isdrag) = true) {startpoint = new point (e. x, E. y); oldpoint = new point (e. x, E. y) ;}} private void picturebox#mouseup (Object sender, mouseeventargs e) {isdrag = false; ig = picturebox1.creategraphics (); Ig. drawrectangle (new pen (color. black, 1), startpoint. x, startpoint. y, E. x-startpoint. x, E. y-startpoint. y); therectangle = new rectangle (startpoint. x, startpoint. y, E. x-startpoint. x, E. y-startpoint. y);} private void picturebox#mouseclick (Object sender, mouseeventargs e) {try {// graphics = This. creategraphics (); Bitmap bitmap = new Bitmap (picturebox1.image); bitmap clonebitmap = bitmap. clone (therectangle, pixelformat. dontcare); picturebox2.image = (image) clonebitmap; // graphics. drawimage (clonebitmap, E. x, E. y); graphics G = picturebox1.creategraphics (); solidbrush mybrush = new solidbrush (color. transparent); G. fillrectangle (mybrush, therectangle);} catch {}}}}