Using system;using system.collections.generic;using system.componentmodel;using system.data;using System.Drawing; Using system.linq;using system.text;using system.threading.tasks;using system.windows.forms;using System.IO;// Import namespace namespace windowsformsapplication4{public partial class Form1:form {public Form1 () { InitializeComponent (); private void Form1_Load (object sender, EventArgs e) {} private void Statusstrip1_itemclicke D (object sender, ToolStripItemClickedEventArgs e) {} private void Lookup Toolstripmenuitem_click (object s Ender, EventArgs e) {} private void cut Ttoolstripmenuitem_click (object sender, EventArgs e) { Textbox1.cut (); } private void Copy Ctoolstripmenuitem_click (object sender, EventArgs e) {textbox1.copy (); } private void Paste Ptoolstripmenuitem_click (object sender, EventArgs e) {TexTbox1.paste (); } private void Select all Atoolstripmenuitem_click (object sender, EventArgs e) {textbox1.selectall (); } private void Undo Utoolstripmenuitem_click (object sender, EventArgs e) {Textbox1.undo (); } private void opens Otoolstripmenuitem_click (object sender, EventArgs e) {//Create Open File dialog box: Implement find text on hard disk Path//OpenFileDialog openfiledialong1=new OpenFileDialog ();//Create object//You can build a OpenFileDialog object in the interface F caps Openfiledialog1.filter = "Text document |*.txt| all Files |*.*";//filter DialogResult isOK = Openfiledialog1.showdialog (); Displays the return value of the dialog enumeration type if (isOK = = DialogResult.OK)//To determine if the point is opened by the return value of the dialog box {//Get file path string filename = Openfiledialog1.filename; Read files based on file path: stream is used to read the stream://filestream fs = new FileStream (Filename,filemode.open) that is specifically used for internal disks and inches to interact, read and write; StreamReader sr = new StreamReader (fs,encoding.dEfault);//Stream reader StreamReader sr = new StreamReader (filename, encoding.default); String text = Sr. ReadToEnd ();//Read Sr. Close (); Fs. Close (); TextBox1.Text = Text; } } }}
Winfrom Text Document Open