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 notepad
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void 字体ToolStripMenuItem_Click(object sender, EventArgs e)
{
fontDialog1.ShowDialog();
richTextBox1.Font = fontDialog1.Font;
}
private void 颜色ToolStripMenuItem_Click(object sender, EventArgs e)
{
fontDialog1.ShowDialog();
richTextBox1.ForeColor = fontDialog1.Color;
}
private void 新建ToolStripMenuItem_Click(object sender, EventArgs e)
{
string path = "e:\text.txt";
string content = richTextBox1.Text;
if (string.IsNullOrEmpty(path) == true)
{
MessageBox.Show("文件路径不正确");
return;
}
try
{
FileStream myfs = new FileStream(path, FileMode.Create);
StreamWriter mysw = new StreamWriter(myfs);
mysw.Write(content);
mysw.Close();
myfs.Close();
MessageBox.Show("创建成功");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message .ToString ());
}
}
private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
{
string[] drivers = System.Environment.GetLogicalDrives();
foreach (string driver in drivers )
{
NewMethod(driver);
}
}
private static void NewMethod(string path)
{
string content;
try
{
FileStream myfs = new FileStream(path, FileMode.Open);
StreamReader mysr = new StreamReader(myfs);
content = mysr.ReadToEnd();
RichTextBox richtextbox = new RichTextBox();
richtextbox.Text = content;
mysr.Close();
myfs.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message .ToString ());
}
}
private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
{
string path = "e:\\text.txt";
if (string.IsNullOrEmpty(path) == true)
{
MessageBox.Show("路径不正确");
}
File.Copy(path, "e:\\text.txt");
MessageBox.Show("保存成功");
}
private void 另存为ToolStripMenuItem_Click(object sender, EventArgs e)
{
saveFileDialog1.ShowDialog();
string path = (string )saveFileDialog1.Tag;
File.Copy("e:\\text.txt",path);
}
private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void 日期ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (this.日期ToolStripMenuItem.Checked ==true )
{
this.dateTimePicker1.Show();
}
}
private void 全选ToolStripMenuItem_Click(object sender, EventArgs e)
{
bool c = false;
if (全选ToolStripMenuItem.Checked ==true )
{
this.richTextBox1.SelectAll();
全选ToolStripMenuItem.Checked = c;
}
}
public void 查找ToolStripMenuItem_Click(object sender, EventArgs e)
{
find f = new find();
string ss=richTextBox1.SelectedText.ToLower();
f.ss = ss;
f.Show();
}
}
}
查找
namespace notepad
{
public partial class find : Form
{
public find()
{
InitializeComponent();
}
private void find_Load(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
public string ss = "";
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == null)
{
button1.Enabled = false;
}
else
{
button1.Enabled = true;
}
Form1 f = new Form1();
if (checkBox1.Checked==false)
{
string s = textBox1.Text.Trim().ToLower();
if (f.Text.LastIndexOf(ss) > f.Text.IndexOf(ss))
{
MessageBox.Show("exists");
}
}
}
}
}
浙公网安备 33010602011771号