Simple Notepad function Implementation code-(Stream reader)

Source: Internet
Author: User
Tags print object

usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.IO;//Import Namespaces--streamnamespacewindowsformsapplication2{ Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); }        Private voidShear Ttoolstripmenuitem_click (Objectsender, EventArgs e)        {textbox1.cut (); }        Private voidCopy Ctoolstripmenuitem_click (Objectsender, EventArgs e)        {textbox1.copy (); }        Private voidPaste Ptoolstripmenuitem_click (Objectsender, EventArgs e)        {Textbox1.paste (); }        Private voidSelect All Atoolstripmenuitem_click (Objectsender, EventArgs e)        {Textbox1.selectall (); }        Private voidUndo Utoolstripmenuitem_click (Objectsender, EventArgs e)        {Textbox1.undo (); }        Private stringFileName; Private voidOpen Otoolstripmenuitem_click (Objectsender, EventArgs e) {            //Create Open File dialog box: Help us to find the file path on the hard disk//OpenFileDialog openfiledialog1 = new OpenFileDialog ();//Creating ObjectsOpenfiledialog1.filter ="text files |*.txt| All files |*.*";//FilterDialogResult isOK = Openfiledialog1.showdialog ();//Show dialog Box            if(isOK = = DialogResult.OK)//The return value of the dialog box determines whether the point's Open button            {                 //Get file path                stringfilename =Openfiledialog1.filename; FileName=filename; //read files According to file path: Using streams to read//FileStream fs = new FileStream (Filename,filemode.open); //StreamReader sr = new StreamReader (fs,encoding.default);//Stream Reader--encoding.default select default encodingStreamReader sr =NewStreamReader (Filename,encoding.default); stringText = Sr. ReadToEnd ();//ReadSr.               Close (); //FS. Close ();TextBox1.Text=text; }        }        Private voidSave Stoolstripmenuitem_click (Objectsender, EventArgs e) {            if(FileName! ="") {FileStream fs=NewFileStream (FileName, FileMode.Create); StreamWriter SW=NewStreamWriter (FS, Encoding.default);//Stream WriteSW.                Write (TextBox1.Text); Sw.                Close (); Fs.            Close (); }            Else{SaveFileDialog Savefiledialog1=NewSaveFileDialog (); Savefiledialog1. Filter="text files |*.txt| All files |*.*"; DialogResult isOK=Savefiledialog1.                ShowDialog (); if(isOK = =DialogResult.OK) {stringfilename =Savefiledialog1.                    FileName; FileStream FS=NewFileStream (filename, filemode.create); StreamWriter SW=NewStreamWriter (FS, Encoding.default);//Stream WriteSW.                    Write (TextBox1.Text); Sw.                    Close (); Fs.                Close (); }            }        }        Private voidExit Xtoolstripmenuitem_click (Objectsender, EventArgs e) {             This.        Close (); }        Private voidFind Toolstripmenuitem_click (Objectsender, EventArgs e) {Form2 F=NewForm2 (Textbox1.selectedtext, This); F.owner= This;        F.show (); }        Private voidReplace Toolstripmenuitem_click (Objectsender, EventArgs e) {                   }        Private voidPrint Preview Vtoolstripmenuitem_click (Objectsender, EventArgs e)        {Printpreviewdialog1.showdialog (); }        Private voidPrint Ptoolstripmenuitem_click (Objectsender, EventArgs e) {printdialog1.document= PrintDocument1;//Specify the Print object that corresponds to the Print dialog boxDialogResult isOK =Printdialog1.showdialog (); if(isOK = =DialogResult.OK) {printdocument1.print ();//Print a document            }        }        Private voidPrintdocument1_printpage (Objectsender, System.Drawing.Printing.PrintPageEventArgs e) {            //Set Print contentFont f =NewSystem.Drawing.Font ("Song Body",6); E.graphics.drawstring (Textbox1.text,f,system.drawing.brushes.black,NewPointF (0,0)); }    }}

Using a stream reader to note a reference to a namespace

Simple Notepad function Implementation code-(Stream reader)

Related Article

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.