Method 1: If the aspect ratio of the image to be loaded is not too unbalanced, you can change the sizemode attribute of picturebox to pictureboxsizemode. stretchimage. In this way, the image loaded into the picturebox will be filled with the entire picturebox. However, this method is not very good when the aspect ratio of an image is large. You can select method 2.
Method 2: http://www.cnblogs.com/fengzanfeng/articles/1339107.html
Openfiledialog ofdpic = new openfiledialog (); ofdpic. filter = "JPG (*. JPG ;*. JPEG); GIF file (*. GIF) | *. JPG ;*. JPEG ;*. GIF "; ofdpic. filterindex = 1; ofdpic. filename = ""; if (ofdpic. showdialog () = dialogresult. OK) {string spicpaht = ofdpic. filename. tostring (); bitmap BMP Ic = new Bitmap (spicpaht); point ptloction = new point (bmp ic. size); If (ptloction. x> mypicbox. size. width | ptloction. y> mypicbox. size. height) {// call method of the Photo Frame // pcbpic. dock = dockstyle. fill; // fill the photo box with a portrait, and the proportion of the photo watermark is mypicbox. sizemode = pictureboxsizemode. zoom;} else {// consumer image in the portrait box mypicbox. sizemode = pictureboxsizemode. centerimage ;}
// Loadasync: Non-synchronous ingress like mypicbox. loadasync (spicpaht );}