c# 记事本实现代码
2009-06-11 08:31:56 来源:WEB开发网编辑模块只实现了全选和时间2个功能,自动换行的功能还没写。
如果需要全部源码的请留言或者发邮件至henanlinzhoulcl@163.com
版本:1.0
主要代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace MyNotePad
{
public partial class MyNotePad : Form
{
public MyNotePad()
{
InitializeComponent();
this.toolStripStatusLabel3.Text = DateTime.Now.DayOfWeek.ToString();
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
//textBox1.Text += e.KeyChar;
}
private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void 日期ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (this.textBox1.SelectedText != "")
{
this.textBox1.SelectedText = DateTime.Now.ToString();
}
else
{
this.textBox1.Text += DateTime.Now;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
this.toolStripStatusLabel1.Text = "现在时间是:" + DateTime.Now.ToString();
}
private void 状态栏ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (this.statusStrip1.Visible == false)
{
this.statusStrip1.Visible = true;
}
else
{
this.statusStrip1.Visible = false;
this.textBox1.Height += 10;
}
}
private void 关于MyNotePadAToolStripMenuItem_Click(object sender, EventArgs e)
{
About ab = new About();
ab.Show();
}
private void 全选ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.textBox1.SelectAll();
}
private void 字体ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (fontDialog1.ShowDialog() == DialogResult.OK)
{
textBox1.Font = fontDialog1.Font;
}
}
private void MyNotePad_Resize(object sender, EventArgs e)
{
this.panel1.Width = this.Size.Width - 25;
this.panel1.Height = this.Size.Height - 50;
this.textBox1.Width = this.panel1.Width;
this.textBox1.Height = this.panel1.Height;
}
private void 自动换行ToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
{
using (SaveFileDialog saveDig = new SaveFileDialog())
{
saveDig.Filter = @"文本文档(*.txt)|*.txt";
saveDig.FileName = "*.txt";
if (saveDig.ShowDialog() == DialogResult.OK)
{
StreamWriter sw = new StreamWriter(saveDig.FileName, false, System.Text.Encoding.Default);
sw.Write(this.textBox1.Text);
sw.Close();
this.Text = saveDig.FileName;
}
}
}
private void 另存为ToolStripMenuItem_Click(object sender, EventArgs e)
{
using (SaveFileDialog saveDig = new SaveFileDialog())
{
saveDig.Filter = @"文本文档(*.txt)|*.txt";
saveDig.FileName = this.Text;
if (saveDig.ShowDialog() == DialogResult.OK)
{
StreamWriter sw = new StreamWriter(saveDig.FileName, false, System.Text.Encoding.Default);
sw.Write(this.textBox1.Text);
sw.Close();
}
}
}
private void 新建ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (this.textBox1.Text != "")
{
更多精彩
赞助商链接