Small text editor

xiaoxiao2021-03-06  81

Http://true5460.muicc.com/program/textedit.zip ----------------------------------- -------------------------------------------------------------------------------- "Using system.collections; using system.ComponentModel Using system.windows.forms; using system.data; using system.text;

A summary description of Namespace WindowsApplication1 {///

/// Form1. /// public class Form1: System.Windows.Forms.Form {private System.Windows.Forms.Label label1; private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.TextBox textBox2; private System.Windows.Forms.Label label2; private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; private System.Windows.Forms.Button button3; private System.Windows.Forms.Button button4; private System.windows.Forms.Button Button5; private system.windows.Forms.Button Button6; private system.windows.Forms.Button Button7; /// // / / The designer variable. /// private system.componentmodel.container components = null;

Public Form1 () {// // Windows Form Designer Support for // InitializeComponent ();

// // Todo: Add any constructor code after INITIALIZEComponent call //}

///

/// Clean all the resources being used. /// Protected Override Void Dispose (Bool Disposing) {if (disponents! = Null) {components.dispose ();}} Base.Dispose (4);

#REGION Windows Form Designer The code ///

/// designer supports the required method - do not use the code editor to modify the // / this method.

/// private void InitializeComponent () {this.label1 = new System.Windows.Forms.Label (); this.textBox1 = new System.Windows.Forms.TextBox (); this.textBox2 = new System. Windows.Forms.TextBox (); this.label2 = new system.windows.forms.label (); this.button1 = new system.windows.Forms.Button (); this.button2 = new system.windows.Forms.Button (); This.Button3 = new system.windows.Forms.Button (); this.button4 = new system.windows.Forms.Button (); this.button5 = new system.windows.Forms.Button (); this. Button6 = new system.windows.Forms.Button (); this.button7 = new system.windows.forms.button (); this.suspendlayout (); // // label1 // this.label1.font = new system. Drawing.Font ("Song", 9F, System.drawing.FontStyle.regular, System.drawing.graphicsUnit.Point (134)); this.Label1.Location = new system.drawing.point (24, 8); this.label1.name = "label1"; this.label1.size = new system.drawing.size (56, 16); this.Label1.tabindex = 0; this.l Abel1.text = "file name"; ///////////////////////////////////////ww.nchorstyles (((System.Windows.Forms.Anchorstyles.top | System.Windows.Forms .Anchorstyles.Lorms.Anchorstyles.right)); this.textbox1.location = new system.drawing.point (24, 32); this.textbox1.name = "textbox1"; this.TextBox1 .Size = new system.drawing.size (304, 21); this.textBox1.tabindex = 1; this.textBox1.text = ""; /// textbox2 // this.textBox2.anchor =

((System.Windows.Forms.AnchorStyles) ((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows. Forms.AnchorStyles.Right))); this.textBox2.Location = new System.Drawing.Point (24, 85); this.textBox2.Multiline = true; this.textBox2.Name = "textBox2"; this.textBox2.ScrollBars = System.Windows.Forms.Scrollbars.vertical; this.textbox2.size = new system.drawing.size (408, 283); this.textbox2.tabindex = 2; this.textBox2.text = ""; /////// Label2 // this.label2.location = new system.drawing.point (21, 64); this.label2.name = "label2"; this.label2.size = new system.drawing.size (56, 16); this .label2.tabindex = 3; this.label2.text = "file content"; // // button1 // this.button1.anchor = ((System.Windows.Forms.Anchorstyles) ((System.Windows.Forms.Anchbook .Top | system.windows.forms.Anch.Anchorstyles.right)))))))); this.button1.location = new system.drawing.point (504, 80); this.bu Tton1.name = "button1"; this.button1.tabindex = 4; this.button1.text = "creation"; this.button1.click = new system.eventhandler (this.button1_click); // // Button2 // This.Button2.Anchor = (System.Windows.Forms.Anchorstyles) ((System.Top | System.Windows.Forms.Anchorstyles.right))); this.button2.location = new system. Drawing.point (504, 136); this.button2.name = "button2"; this.button2.tabindex = 5; this.button2.text = "Read"; this.button2.click = new system.eventhandler this.button2_click;

// // button3 // this.button3.ancy = ((System.windows.Forms.Anchorstyles) ((System.Windows.Forms.Anchorseles.top | System.Windows.Forms.Anchorstyles.right)))); this. Button3.location = new system.drawing.point (504, 192); this.button3.name = "button3"; this.button3.tabindex = 6; this.button3.text = "append"; this.button3.click = New System.EventHandler (this.Button3_Click); // // Button4 // this.button4.Anchor = ((System.Windows.Forms.Anchorstyles.top | System.Windows. Forms.anchorstyles.right))))))))))))))))); this.button4.location = new system.drawing.point (504, 360); this.button4.name = "button4"; this.button4.tabindex = 7; this.button4.text = "Exit"; this.button4.click = new system.eventhandler (this.button4_click); // // button5 // this.button5.Anchor = ((System.Windows.Forms.Anchorstyles) ((System.Windows) .Form | system.windows.Forms.Anchorstyles.right))); this.button5.location = new system.drawing.po Int (504, 248); this.button5.name = "button5"; this.button5.tabindex = 8; this.button5.text = "Clear"; this.button5.click = new system.eventhandler (this.button5_click ); // // button6 // this.button6.Anchor = ((System.Windows.Forms.Anchorstyles) ((System.Windows.Forms.Anchorstyles.top | System.Windows.Forms.Anchorstyles.right))))); This.Button6.Location = new system.drawing.point (344, 32); this.button6.name = "button6"; this.button6.size = new system.drawing.size (64, 23); this.button6. TabINDEX = 9; this.button6.text = "Browse";

This.Button6.Click = new system.EventHandler (this.button6_click_1); // // Button7 // this.button7.Anchor = ((System.Windows.Forms.Anchorstyles) ((System.Windows.Forms.Anchorstyles. " Top | System.Windows.Forms.Anchorstyles.right)))))))))))))))))))))))))))))))))); this.Button7.Location = new system.drawing.point (504, 304); this.button7.name = "button7"; this.button7.tabindex = 10 This.button7.text = "copy"; this.button7.click = new system.eventhandler (this.button7_click); // // form1 // this.autoscalebasesize = new system.drawing.size (6, 14) This.clientsize = new system.drawing.size (640, 430); this.controls.add (this.button7); this.controls.add (this.button6); this.Controls.add (this.button5); This.Controls.add (this.button4); this.controls.add (this.button3); this.Controls.add (this.button2); this.controls.add (this.button1); this.controls.add ( THIS.LABEL2); this.Controls.add (this.TextBox2); this.Controls.add (this.TextBox1); this.controls.add (this.Label1); this.name = "f ORM1 "; this.StartPosition = system.windows.forms.formstartPosition.centerscreen; this.text =" text editor _swl "; this.ResumeLayout (false);} #ENDREGION

///

/// The primary entry point of the application. /// [stathread] static void main () {Application.run (new form1 ());}

private void button3_Click (object sender, System.EventArgs e) {FileStream file; StreamWriter file_in; String filename = textBox1.Text; if (filename == "") MessageBox.Show ( "/ n space file name, enter a file name! "," Wrong operation "); else {try {file = new filestream (filename, filemode.Append); file_in = new streamwriter (file, encoding.default); file_in.write (TextBox2.text); file_in.close () File.close (); MessageBox.show ("Successful operation!", "Success");} catch {messagebox.show ("/ n error operation!", "Error operation");}}} private void button1_click Object sender, system.eventargs e) {filestream file; streamwriter file_in; string filename = textbox1.text; if (filename == ") MessageBox.show (" / n file name empty, please enter the file name! "," Error " Operation "); else {try {file = new filestream (filename, filemode.create); file_in = new streamwriter (file, encoding.default); file_in.write (); file_in.close (); file.close (); file.close (); MessageBox.show ("Successful operation!", "Success ! ");} Catch {messagebox.show (" / n error)! "," Wrong operation ");}}}

private void button2_Click (object sender, System.EventArgs e) {FileStream file; StreamReader file_out; String content, filename = textBox1.Text; textBox2.Text = ""; if (filename == "") MessageBox.Show ( "/ n File name, please enter the file name! "," Error operation "); else {try {file = new filestream (filename, filemode.open); file_out = new streamreader (file, encoding.default); while ((content = File_out.readline ())! = null) {textBox2.text = content "/ r / n"; file_out.close (); file.close (); messagebox.show ("Successful operation!", "success") Catch {messagebox.show ("/ n error!", "Error operation");}}} private void button4_click (object sender, system.eventargs e) {Application.exit ();

Private Void Button5_Click (Object Sender, System.EventArgs E) {textBox2.clear ();

private void button6_Click_1 (object sender, System.EventArgs e) {OpenFileDialog openFileDialog1 = new OpenFileDialog (); openFileDialog1.InitialDirectory = ""; openFileDialog1.Filter = "txt files (* .txt) | * .txt | All files (*. *) | *. * "; OpenFiledialog1.filterIndex = 2; openfiledialog1.restoredirectory = false;

IF (OpenFileDialog1.Showdialog () == DialogResult.ok) {textbox1.text = OpenFiledialog1.FileName;}

}

Private void button7_click (object sender, system.eventargs e) {if (TextBox2.text == ") MessageBox.show (" There is no information in the text box! "," Warning "); else {textbox2.selectall (); TextBox2 .Copy (); messagebox.show ("The text has been made to the clipboard!", "Success");}}

}

转载请注明原文地址:https://www.9cbs.com/read-96629.html

New Post(0)