Private voidButton1_Click (Objectsender, EventArgs e) { //Click the popup dialog boxOpenFileDialog OFD =NewOpenFileDialog (); //setting the caption of a dialog boxOfd. Title ="Please select the text file you want to open yo O (∩_∩) o haha"; //The Settings dialog box can be multiple-selectOfd. MultiSelect =true; //setting the initial directory of the dialog boxOfd. InitialDirectory =@"C:\Users\Administrator\Desktop"; //set the file type of the dialog boxOfd. Filter ="text files |*.txt| media files |*.wmv| All files |*.*"; //Show dialog BoxOFD. ShowDialog (); //get the path to the file selected in the Open dialog box stringPath =OFD. FileName; if(Path = ="") { return; } using(FileStream fsread =NewFileStream (Path, FileMode.Open, FileAccess.Read)) { byte[] buffer =New byte[1024x768*1024x768*5]; //the number of bytes actually read intr = Fsread.read (buffer,0, buffer. Length); TextBox1.Text= Encoding.Default.GetString (buffer,0, R); } }
Save dialog box:
Private voidButton1_Click (Objectsender, EventArgs e) {SaveFileDialog SFD=NewSaveFileDialog (); SfD. Title="Please select a path to save"; SfD. InitialDirectory=@"C:\Users\Administrator\Desktop"; SfD. Filter="text files |*.txt| All files |*.*"; SfD. ShowDialog (); //get the path to the saved file stringPath =SFD. FileName; if(Path = ="") { return; } using(FileStream fswrite =NewFileStream (Path,filemode.openorcreate,fileaccess.write)) { byte[] buffer =Encoding.Default.GetBytes (TextBox1.Text); Fswrite.write (Buffer,0, buffer. Length); } MessageBox.Show ("saved successfully"); }
Fonts and Colors dialog box
/// <summary> ///Font dialog Box/// </summary> /// <param name= "Sender" ></param> /// <param name= "E" ></param> Private voidButton1_Click (Objectsender, EventArgs e) {FontDialog FD=NewFontDialog (); Fd. ShowDialog (); Textbox1.font=FD. Font; } /// <summary> ///Color dialog box/// </summary> /// <param name= "Sender" ></param> /// <param name= "E" ></param> Private voidButton2_Click (Objectsender, EventArgs e) {ColorDialog CD=NewColorDialog (); Cd. ShowDialog (); Textbox1.forecolor=CD. Color; }
. NET Learning notes----2015-07-02 (select File dialog box, Save dialog box, font and Color dialog box)