分享
 
 
 

小的文本编辑器

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

http://true5460.muicc.com/program/textEdit.zip

--------------------------------------------------------------------

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

using System.IO;

using System.Text;

namespace WindowsApplication1

{

/// <summary>

/// Form1 的摘要说明。

/// </summary>

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;

/// <summary>

/// 必需的设计器变量。

/// </summary>

private System.ComponentModel.Container components = null;

public Form1()

{

//

// Windows 窗体设计器支持所必需的

//

InitializeComponent();

//

// TODO: 在 InitializeComponent 调用后添加任何构造函数代码

//

}

/// <summary>

/// 清理所有正在使用的资源。

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

#region Windows 窗体设计器生成的代码

/// <summary>

/// 设计器支持所需的方法 - 不要使用代码编辑器修改

/// 此方法的内容。

/// </summary>

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("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(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.label1.Text = "文件名";

//

// textBox1

//

this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)

| System.Windows.Forms.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 = "文件内容";

//

// button1

//

this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));

this.button1.Location = new System.Drawing.Point(504, 80);

this.button1.Name = "button1";

this.button1.TabIndex = 4;

this.button1.Text = "创建";

this.button1.Click += new System.EventHandler(this.button1_Click);

//

// button2

//

this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.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 = "读取";

this.button2.Click += new System.EventHandler(this.button2_Click);

//

// button3

//

this.button3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.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 = "追加";

this.button3.Click += new System.EventHandler(this.button3_Click);

//

// button4

//

this.button4.Anchor = ((System.Windows.Forms.AnchorStyles)((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 = "退出";

this.button4.Click += new System.EventHandler(this.button4_Click);

//

// button5

//

this.button5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));

this.button5.Location = new System.Drawing.Point(504, 248);

this.button5.Name = "button5";

this.button5.TabIndex = 8;

this.button5.Text = "清除";

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 = "浏览";

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 = "复制";

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 = "Form1";

this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;

this.Text = "文本编辑器_swl";

this.ResumeLayout(false);

}

#endregion

/// <summary>

/// 应用程序的主入口点。

/// </summary>

[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 文件名空,请输入文件名! ","错误操作");

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(" 操作成功! ","成功");

}

catch

{

MessageBox.Show("\n 错误操作! ","错误操作");

}

}

}

private void button1_Click(object sender, System.EventArgs e)

{

FileStream file;

StreamWriter file_in;

String filename=textBox1.Text;

if(filename=="") MessageBox.Show("\n 文件名空,请输入文件名! ","错误操作");

else

{

try

{

file=new FileStream(filename,FileMode.Create);

file_in=new StreamWriter(file,Encoding.Default);

file_in.Write(textBox2.Text);

file_in.Close();

file.Close();

MessageBox.Show(" 操作成功! ","成功!");

}

catch

{

MessageBox.Show("\n 错误操作! ","错误操作");

}

}

}

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 文件名空,请输入文件名! ","错误操作");

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(" 操作成功! ","成功");

}

catch

{

MessageBox.Show("\n 错误操作! ","错误操作");

}

}

}

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(" 文本框内无信息! ","警告");

else

{

textBox2.SelectAll();

textBox2.Copy();

MessageBox.Show(" 已将文本制到剪贴板! ","成功");

}

}

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有