C# winform 编写记事本

2021-04-21 02:28

阅读:657

 

技术分享图片技术分享图片

 

 

//用colorDialog窗口控件设置字体颜色
private void toolStripButton1_Click(object sender, EventArgs e)
{
DialogResult drt = colorDialog1.ShowDialog();
if (drt == DialogResult.OK)
{
richTextBox1.ForeColor = colorDialog1.Color;
}
}
//读取文件路径
private void toolStripButton5_Click(object sender, EventArgs e)
{
DialogResult drt = folderBrowserDialog1.ShowDialog();
if (drt==DialogResult.OK)
{
MessageBox.Show(folderBrowserDialog1.SelectedPath);

}


}
//用fontDialog窗体控件设置字体样式
private void toolStripButton2_Click(object sender, EventArgs e)
{
DialogResult drt = fontDialog1.ShowDialog();
if (drt==DialogResult.OK)
{
richTextBox1.Font = fontDialog1.Font;
}
}
//用openFileDialog控件打开文件
private void toolStripButton3_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "文本文档(*.txt)|*.txt|所有文件(*.*)|*.*";
DialogResult drt = openFileDialog1.ShowDialog();
if (drt==DialogResult.OK)
{
richTextBox1.LoadFile(openFileDialog1.FileName,RichTextBoxStreamType.PlainText);
}
}
//打开文本文件中的超链接
private void richTextBox1_LinkClicked(object sender, LinkClickedEventArgs e)
{
System.Diagnostics.Process.Start(e.LinkText);
}
//用saveFileDialog控件保存文件
private void toolStripButton4_Click(object sender, EventArgs e)
{
saveFileDialog1.Filter = "文本文档(*.txt)|*.txt";
DialogResult drt = saveFileDialog1.ShowDialog();
if (drt==DialogResult.OK)
{
MessageBox.Show(saveFileDialog1.FileName);
richTextBox1.SaveFile(saveFileDialog1.FileName,RichTextBoxStreamType.PlainText);
}
}


评论


亲,登录后才可以留言!