ColorDialog: Displays the available colors, as well as controls that users can customize colors, appear as a Palette dialog box, and optionally change the font color
FolderBrowserDialog: displays a dialog box prompting the user to select a folder
FontDialog: Displays a Select Font dialog box to add the Adjust color function to change the Showcolor default value in the property behavior of this control to true
OpenFileDialog: displays a dialog box prompting the user to open the file
SaveFileDialog: displays a dialog box prompting the user to choose where to save the file
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.IO;//Reference StreamusingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespacedialog box control { Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); } Private voidOpen Otoolstripmenuitem_click (Objectsender, EventArgs e) { //open a local file because it is not supported to display other files in Notepad, so first set the format of the open fileOpenfiledialog1.filter ="text files |*.txt| All files |*.*";//The front is the Chinese characters added, can be set freely, the middle vertical bar, followed by the format, *.txt, value open txt type fileDialogResult Dr= Openfiledialog1.showdialog ();//DialogResult indicates the return value in the dialog box, which is used to receive the dialog box selection to determine the execution after if(dr = = DialogResult.OK)//if the return value is OK, DialogResult.OK, then do the following, add this step just to make the program more rigorous{Label1. Text= Openfiledialog1.filename;//Add a text display control Label1, the selection path of the open file is displayed inside,//. FileName Gets the string of the selected file name in the file dialog box, that is, the save path is taken as a string//StreamReader Stream, the file's transmission channel, only through this to complete the opening or transmission of the file//to refer to this method before use, and then instantiate, by selecting the path will open the file received in the flow channelStreamReader sr =NewStreamReader (openfiledialog1.filename); TextBox1.Text= Sr. ReadToEnd ();//Sr. ReadToEnd (); Read stream from start read to end, display in text boxSr. Close ();//when the circulation channel is finished, remember to close it . } } //Save function stringPath ="";//define a string variable to determine whether it is empty Private voidSave Stoolstripmenuitem_click (Objectsender, EventArgs e) { if(Path = ="")//The first time you come in, the variable you defined is empty, so take this step .{savefiledialog1.filename="new text file. txt";//set the saved file type firstSavefiledialog1.showdialog ();//Displays the File Save dialog box to perform the SavePath = Savefiledialog1.filename;//receives the Save path as a string in the variable path } //If you saved it once, add the new content to the Notepad in the save path, then click Save,//The variable path has been assigned the first time it was saved and is not empty, just take the following step//use a stream to get to a file by saving a pathStreamWriter SW =NewStreamWriter (path); Sw. Write (TextBox1.Text);//write the newly added content directly to the save pathSw. Close ();//The circulation channel is closed after use } Private voidSave As Atoolstripmenuitem_click (Objectsender, EventArgs e) { //Save as and save, just do not need to determine whether there is no saved text, each time is a new saveSavefiledialog1.filename ="new text file. txt"; Savefiledialog1.showdialog (); Label1. Text=Savefiledialog1.filename; StreamWriter SW=NewStreamWriter (savefiledialog1.filename); Sw. Write (TextBox1.Text); Sw. Close (); } Private voidExit Xtoolstripmenuitem_click (Objectsender, EventArgs e) { This. Close ();//mouse Click to implement the Exit } Private voidUndo Utoolstripmenuitem_click (Objectsender, EventArgs e) {Textbox1.undo ();//mouse Click to implement the input text revocation } Private voidShear Ttoolstripmenuitem_click (Objectsender, EventArgs e) {textbox1.cut ();//mouse click to achieve text cut } Private voidCopy Ctoolstripmenuitem_click (Objectsender, EventArgs e) {textbox1.copy ();//mouse click to achieve text copy } Private voidPaste Ptoolstripmenuitem_click (Objectsender, EventArgs e) {textbox1.paste ();//mouse click to implement text pasting } Private voidSelect All Atoolstripmenuitem_click (Objectsender, EventArgs e) {Textbox1.selectall ();//mouse Click to achieve the full selection of text } Private voidFont Color Toolstripmenuitem_click (Objectsender, EventArgs e) { //specify an identifier to indicate the return value of the dialog box, and receive the return value of the Font Color dialog box in the DrDialogResult dr =Colordialog1.showdialog (); if(dr = = DialogResult.OK)//if the return value is OK { //The font color is performed, the foreground color of the text box is Textbox1.forecolor equal to the colors selected in the Color dialog boxTextbox1.forecolor =colorDialog1.Color; } } //The dialog box function is displayed with the control name. ShowDialog (), such as the Color Control dialog box, displays Colordialog1.showdialog (); Private voidFont Format Toolstripmenuitem_click (Objectsender, EventArgs e) {Fontdialog1.showcolor=true;//set the font color to available in the font settings control first, and in the design interface propertiesFontdialog1.showdialog ();//Display Font Settings dialog boxTextbox1.font = Fontdialog1.font;//text box textBox1 font is equal to the color selected in the Font Settings dialog boxTextbox1.forecolor = Fontdialog1.color;//The foreground color of the text box, the text color equals the color set in the Font Settings dialog box } Private voidSelect Folder Toolstripmenuitem_click (Objectsender, EventArgs e) {Folderbrowserdialog1.showdialog ();//The Perform Select Folder feature displays the FolderBrowserDialog1 control name point display,//Select path to display file in text boxTextBox1.Text = Folderbrowserdialog1.selectedpath;//SelectedPath Select Path } Private voidToolstripstatuslabel2_click (Objectsender, EventArgs e) { } Private voidtextBox1_TextChanged (Objectsender, EventArgs e) { strings = textBox1.TextLength.ToString ();//To record and display the number of characters, first assign the length of the Notepad text to the variable s in the form of a stringToolstripstatuslabel2.text = s;//bottom menu Bar text control text value equals the length of the Notepad text } }}
Winform dialog box