The examples in this article describe the use of OpenFileDialog and Pictruebox in C #. Share to everyone for your reference. The specific usage analysis is as follows:
Let's take a look at this piece of code:
String resultfile = ""; OpenFileDialog openFileDialog1 = new OpenFileDialog (); openfiledialog1.initialdirectory = "d:\\ Patch "; openfiledialog1.filter =" All Files (*. *) |*.*|txt files (*.txt) |*.txt "; openfiledialog1.filterindex = 2;o Penfiledialog1.restoredirectory = true; if (openfiledialog1.showdialog () = = DialogResult.OK) resultfile = Openfiledialog1.filename;
Resultfile will get you the path to the selected file
The OpenFileDialog control has the following basic properties
InitialDirectory Initial directory of the dialog box
Filter the file filter to display in the dialog box, for example, "text file (*.txt) |*.txt| All Files (*. *) | | *.*"
FilterIndex the index of the file filter selected in the dialog box, set to 1 if the first item is selected
Restoredirectory Control whether the dialog box restores the current directory before closing
FileName The first file to display in a dialog box or the last selected file
Title displays the characters in the title bar of the dialog box
AddExtension whether to add default extensions automatically
Checkpathexists Check if the specified path exists before the dialog box returns
DEFAULTEXT default name extension
Dereferencelinks whether to dereference a shortcut before returning from the dialog box
ShowHelp Enable the Help button
Validatenames the Control dialog box to check if the file name does not contain invalid characters or sequences
How do I set the filter for the OpenFileDialog component so that I can filter out files with multiple extensions at once?
Dlg. Filter = "Image Files (*. bmp;*. jpg;*. GIF) |*. bmp;*. jpg;*. Gif| All files (*. *) |*.* "
The first parameter is the width of the PictureBox, the second is the height of the PictureBox, and the third is your picture. This method can adjust the image to the appropriate size. You do not set the properties of the SizeMode, through this method to get the appropriate picture, set PictureBox Image property equals this picture, do not set the background map. I don't have a test. You have to test it yourself, if there is still a problem, it is the picture is too small. You need to make a new picture.
Public Image getnewimage (int newimgwidth, int newimgheight, image srcimage) { image newimg = Srcimage.getthumbnailimage (newimgwidth, newimgheight, NULL, New IntPtr ()); Graphics gr = Graphics.fromimage (newimg); Gr. DrawImage (newimg, 0, 0, newimg.width, newimg.height); Gr. Dispose (); return newimg; }
Pictruebox Properties of SizeMode:
Abstract:// The image is placed in the upper-left corner of the System.Windows.Forms.PictureBox. If the image is larger than the system.windows.forms.picturebox//that contains it , the image will be clipped out. Normal = 0,////Abstract:// System.Windows.Forms.PictureBox The image is stretched or shrunk to fit the size of the system.windows.forms.picturebox//. StretchImage = 1,////Summary:// adjusts the System.Windows.Forms.PictureBox size so that it is equal to the size of the included image. AutoSize = 2,////Abstract:// If the System.Windows.Forms.PictureBox is larger than the image, the image will be centered. If the image is larger than system.windows.forms.picturebox//, the picture will be in the center of System.Windows.Forms.PictureBox, and the outer edge will be trimmed off. CenterImage = 3,////Abstract://The image size is increased or decreased by its original size ratio. Zoom = 4,
The above is the content of the usage analysis of OpenFileDialog and Pictruebox in C #, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!