1. 程式人生 > >C# winform 編寫記事本

C# winform 編寫記事本

txt args dia select .com tex ces ont obj

技術分享圖片技術分享圖片

//用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);
}
}

C# winform 編寫記事本