用c#编写的记事本主要应用技术

2024-12-01 08:32:54
推荐回答(3个)
回答(1):

文件的保存,打开,注意所采用的编码格式,就是文件的打开与保存的编码要对应
字符的搜索,定位,替换,这些都可以直接用C#里面richtextbox的方法
拷贝,剪切,粘贴,这些也可用直接用richtextbox的方法
还有就是部分文本的格式设置(包括颜色,字体大小),这部分可以不要,因为记事本功能相对比较简单一点。
这就是我以前做过的功能,其它好像没有了。

回答(2):

private void Form1_Load(object sender, EventArgs e)
{
openFileDialog1.Filter = "文本文件|*.txt|所有文件|*.*";
openFileDialog1.DefaultExt = "*.txt";
openFileDialog1.CheckFileExists = true;
openFileDialog1.CheckPathExists = true;
openFileDialog1.Title = "Load";
openFileDialog1.FileName = "*.txt";
saveFileDialog1.Filter = "文本文件|*.txt|其他文件|*.*";
saveFileDialog1.AddExtension = true;
saveFileDialog1.CreatePrompt = false;
saveFileDialog1.DefaultExt = ".txt";
saveFileDialog1.Title = "Save As";
saveFileDialog1.FileName = "txtfile";
}
private void label1_Click(object sender, EventArgs e)
{
DialogResult od = new DialogResult();
od = openFileDialog1.ShowDialog();
if (od == DialogResult.OK)
{
string name = openFileDialog1.FileName;
StreamReader sr = new StreamReader(name, Encoding.Default);
textBox1.Text = sr.ReadToEnd();
sr.Close();
saveFileDialog1.FileName = openFileDialog1.FileName;
textBox1.Focus();
this.Text = "Memo " + openFileDialog1.FileName;
label2.Text = "Save";
}
else return;
}

private void label2_Click(object sender, EventArgs e)
{
if (saveFileDialog1.FileName == "txtfile")
{
DialogResult sd = new DialogResult();
sd = saveFileDialog1.ShowDialog();
if (sd == DialogResult.OK)
{
StreamWriter saved = new StreamWriter(saveFileDialog1.FileName);
saved.Write(textBox1.Text);
saved.Close();
label2.Text = "Save";
}
else return;
}
else
{
StreamWriter saved2 = new StreamWriter(saveFileDialog1.FileName);
saved2.Write(textBox1.Text);
saved2.Close();
label2.Text = "Save";
}
}

回答(3):

File 文件的保存..