Winform simple use of five commonly used dialog box controls

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.