The production of C # Notepad

Source: Internet
Author: User
Tags print object

I. Implementation of MENU commands

Textbox:
Property:
Text: Literal
SelectedText: Gets or sets the selected text
CanUndo: Is it possible to revoke
Method:
Undo: Undo
Clearundo: emptying the undo buffer
Cut: Cut
Copy: Copying
Paste: Pasting
SelectAll: Select All
dialog box:
ShowDialog (); Displays a dialog box that returns an enumeration type of DialogResult

Colordialog:color property, used to get the color
Folderbrowserdialog:selectedpath Selected Path
The Fontdialog:font property returns a font type value that stores the settings for the font
OpenFileDialog:
FileName Gets or sets the file path that contains the filename
Filenames is an array of file path strings
Filter: File filter format is hint text one |*. suffix | hint text two |*. suffix | hint text three |*. suffix
SAVEFILEDIALOG1:
FileName Gets or sets the file path that contains the filename
Filenames is an array of file path strings
Filter: File filter format is hint text one |*. suffix | hint text two |*. suffix | hint text three |*. suffix

Notepad production:

1. Make a good menu bar with MenuStrip;

2. Set the text box to multiline and set the dock to fill;

3. Set the events for the Edit menu command;

4. Set the event for the "File" menu command;

Note: When setting up a command that requires a popup window, drag the appropriate window tool to the design form in advance, and drag it in the lower part of the form to see the following:

trigger events for individual menu commandsPrivate voidRevoke Toolstripmenuitem_click (Objectsender, EventArgs e) {            if(Textbox1.canundo) {Textbox1.undo (); }        }        Private voidClip Toolstripmenuitem_click (Objectsender, EventArgs e) {            if(Textbox1.selectedtext! =NULL) {textbox1.cut (); }        }        Private voidCopy Toolstripmenuitem_click (Objectsender, EventArgs e) {            if(Textbox1.selectedtext! =NULL) {textbox1.copy (); }        }        Private voidPaste Toolstripmenuitem_click (Objectsender, EventArgs e)        {Textbox1.paste (); }        Private voidDelete Toolstripmenuitem_click (Objectsender, EventArgs e) {            if(Textbox1.selectedtext! =NULL) {Textbox1.selectedtext=""; }        }//to set the event for a File menu command that pops up a dialog box        Private voidFont Toolstripmenuitem_click (Objectsender, EventArgs e) {Fontdialog1.showdialog ();//Display Font dialog box            if(Fontdialog1.font! =NULL)//If the user selects a font, the font size is displayed{MessageBox.Show (fontDialog1.Font.Size.ToString ());} }        Private voidOpen Toolstripmenuitem_click (Objectsender, EventArgs e)        {Openfiledialog1.showdialog (); }        Private voidSave Toolstripmenuitem_click (Objectsender, EventArgs e)            {Savefiledialog1.showdialog (); if(Savefiledialog1.filename! =NULL) {MessageBox.Show (savefiledialog1.filename); }        }
After you press the Font command

Second, read and write data through file stream

Required namespaces: using System. IO;

Flow:
Input stream:
string filename = Openfiledialog1.filename;
Read through the stream for file reading
StreamReader sr = new StreamReader (filename);
TextBox1.Text = Sr. ReadToEnd ();
Sr. Close ();
Output stream:
string filename = Savefiledialog1.filename;
Write a stream, you can create a file on the hard disk, and write information to the file
StreamWriter SW = new StreamWriter (filename);
Sw. Write (This.textBox1.Text);
Sw. Close ();
This: Represents the current object of the class in which it resides

Exercises for input streams:

Private voidOpen Toolstripmenuitem_click (Objectsender, EventArgs e)            {Openfiledialog1.showdialog (); if(Openfiledialog1.filename! =NULL)//If the user selects a file, the text that is read into the file            {                stringOpenFileName =Openfiledialog1.filename; StreamReader SR=NewStreamReader (OPENFILENAME);//Create a file stream object with the filename as a parametertextbox1.text= Sr. ReadToEnd ();//Transfer the text you read to a text boxSr.close ();//Remember to close the file stream when you're done            }                     }

Find the Aaa.txt on the desktop, click Open, you can see the text box has text


Print:
Print dialog box: PrintDialog
Page Setup: PageSetupDialog
Both dialog boxes need to be set PrintDocument to specify the print object
PrintDocument: Print objects, must have, a piece of artboard, for the printer and print content between the transfer, the printer is printed printdoment
Printdocument1_printpage: event, triggered before each page printed, used to specify print content for PrintDocument
Draw the content onto the page of the printed object through the artboard:
System.Drawing.Font f = new System.Drawing.Font ("Arial", 12);
E.graphics.drawstring (textbox1.text,f,system.drawing.brushes.aqua,5,5);
Last Print: Print dialog box, if the print dialog returns to confirm printing, execute printdocument.print ();

Tip: ctrl+e+d automatic alignment;
After the function name, enter a "(" or the cursor in () press ctrl+shift+ space, you can view the overloaded content.

Use function considerations: whether the content to invoke is determined to exist;
Under what conditions need to call;

The production of C # Notepad

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.