OpenFileDialog (Open File dialog box)
FolderBrowserDialog (Browse for Folder dialog box)
SaveFileDialog (Save File dialog box)
ColorDialog (Color dialog box)
FontDialog (Font dialog box)
1 Private voidButton1_Click (Objectsender, EventArgs e)2 {3OpenFileDialog OFD =NewOpenFileDialog ();4Ofd.title ="Select data File";//dialog box title5Ofd.filter ="All Files (*. *) |*.*| Excel file (*.xls;*.xlsx) |*.xls;*.xlsx";//Set file name Filters6Ofd.multiselect =true;//Whether you can select multiple files7 if(Ofd.showdialog () = =DialogResult.OK)8 {9TextBox1.Text =Ofd.filename;Ten } One } A - Private voidButton2_Click (Objectsender, EventArgs e) - { theFolderBrowserDialog FBD =NewFolderBrowserDialog (); -Fbd.description ="Please select a folder";//description text displayed on the control -Fbd.rootfolder = Environment.SpecialFolder.Desktop;//set the root folder to start browsing -Fbd.shownewfolderbutton =true;//whether to display the new Folder button + if(Fbd.showdialog () = =DialogResult.OK) - { +TextBox2.Text =Fbd.selectedpath; A } at } - - Private voidButton3_Click (Objectsender, EventArgs e) - { -SaveFileDialog SFD =NewSaveFileDialog (); -Sfd.title ="Save File dialog box";//dialog box title inSfd.filter ="All Files (*. *) |*.*| Excel file (*.xls;*.xlsx) |*.xls;*.xlsx";//Set file name Filters -Sfd.initialdirectory =@"c:/";//the initial directory displayed by the dialog box toSfd.filename ="Abc.xls";//the file name selected by the dialog box + if(Sfd.showdialog () = =System.Windows.Forms.DialogResult.OK) - { the This. TextBox3.Text =Sfd.filename; * } $ }Panax Notoginseng - Private voidButton4_Click (Objectsender, EventArgs e) the { +ColorDialog CD =NewColorDialog (); A if(CD. ShowDialog () = =System.Windows.Forms.DialogResult.OK) the { + This. Textbox4.text =CD. Color.tostring (); - //This.textBox4.Text = (CD. Color.a + ";" + CD. COLOR.R + ";" + CD. COLOR.G + ";" + CD. COLOR.B). ToString (); $ } $ } - - Private voidButton5_click (Objectsender, EventArgs e) the { -FontDialog SD =NewFontDialog ();Wuyi if(SD. ShowDialog () = =System.Windows.Forms.DialogResult.OK) the { - This. Textbox5.text =SD. Font.FontFamily.Name.ToString (); Wu } -}
View Code
Winform simple use of five commonly used dialog box controls