. NET Learning notes----2015-07-02 (select File dialog box, Save dialog box, font and Color dialog box)

Source: Internet
Author: User

        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)

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: info-contact@alibabacloud.com 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.