C#中关于打开文本更改其中字体并保存的代码
2010-10-06 15:02
381 查看
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Windows;
using System.IO;
namespace exer_2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button4_Click(object sender, EventArgs e)
{
this.Close();
}
private void button2_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
richTextBox1.LoadFile(openFileDialog1.FileName, System.Windows.Forms.
RichTextBoxStreamType.PlainText);
}
private void button3_Click(object sender, EventArgs e)
{
SaveFileDialog saveFile1 = new SaveFileDialog();
saveFile1.DefaultExt = "*.rtf"; ;
saveFile1.Filter = "RTF Files|*.rtf";
if (saveFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK &&
saveFile1.FileName.Length > 0)
{
richTextBox1.SaveFile(saveFile1.FileName, RichTextBoxStreamType.RichNoOleObjs);
}
MessageBox.Show("已保存", "提示:");
}
private void button1_Click(object sender, EventArgs e)
{
fontDialog1.ShowColor = true;
fontDialog1.Font = richTextBox1.SelectionFont;
fontDialog1.Color = richTextBox1.SelectionColor;
if (fontDialog1.ShowDialog() != DialogResult.Cancel)
{
richTextBox1.SelectionFont = fontDialog1.Font;
richTextBox1.SelectionColor = fontDialog1.Color;
}
}
private void richTextBox1_MouseDown(object sender, MouseEventArgs e)
{
this.richTextBox1.TabIndex = 0;
this.richTextBox1.SelectionStart = 0;
this.richTextBox1.SelectionColor = Color.Red;
}
private void richTextBox1_MouseUp(object sender, MouseEventArgs e)
{
this.richTextBox1.SelectionColor = Color.Red;
this.richTextBox1.Show();
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Windows;
using System.IO;
namespace exer_2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button4_Click(object sender, EventArgs e)
{
this.Close();
}
private void button2_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
richTextBox1.LoadFile(openFileDialog1.FileName, System.Windows.Forms.
RichTextBoxStreamType.PlainText);
}
private void button3_Click(object sender, EventArgs e)
{
SaveFileDialog saveFile1 = new SaveFileDialog();
saveFile1.DefaultExt = "*.rtf"; ;
saveFile1.Filter = "RTF Files|*.rtf";
if (saveFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK &&
saveFile1.FileName.Length > 0)
{
richTextBox1.SaveFile(saveFile1.FileName, RichTextBoxStreamType.RichNoOleObjs);
}
MessageBox.Show("已保存", "提示:");
}
private void button1_Click(object sender, EventArgs e)
{
fontDialog1.ShowColor = true;
fontDialog1.Font = richTextBox1.SelectionFont;
fontDialog1.Color = richTextBox1.SelectionColor;
if (fontDialog1.ShowDialog() != DialogResult.Cancel)
{
richTextBox1.SelectionFont = fontDialog1.Font;
richTextBox1.SelectionColor = fontDialog1.Color;
}
}
private void richTextBox1_MouseDown(object sender, MouseEventArgs e)
{
this.richTextBox1.TabIndex = 0;
this.richTextBox1.SelectionStart = 0;
this.richTextBox1.SelectionColor = Color.Red;
}
private void richTextBox1_MouseUp(object sender, MouseEventArgs e)
{
this.richTextBox1.SelectionColor = Color.Red;
this.richTextBox1.Show();
}
}
}
相关文章推荐
- C# 中代码Dialog控件实现(打开,保存,改变字体,颜色,打印功能)
- C# Excel 创建、打开、读取、写入、保存的一般性代码
- C#中创建、打开、读取、写入、保存Excel的一般性代码[转]
- 关于VS的主题、字体、文本颜色的更改与选择
- C#对话框 保存对话框、打开对话框的实现、颜色文件框、字体文本框
- C#中,设置字体,自动换行,保存文件对话框代码
- Winform中代码Dialog控件实现(打开,保存,改变字体,颜色,打印功能)
- 一个WinForm记事本程序(包含主/下拉/弹出菜单/打开文件/保存文件/打印/页面设置/字体/颜色对话框/剪切版操作等等控件用法以及记事本菜单事件/按键事件的具体代码)
- 一段关于打开文件保存文件的代码
- C#中创建、打开、读取、写入、保存Excel的一般性代码
- C#中创建、打开、读取、写入、保存Excel的一般性代码
- [转]C# Excel 创建、打开、读取、写入、保存的一般性代码
- 一个WinForm记事本程序(包含主/下拉/弹出菜单/打开文件/保存文件/打印/页面设置/字体/颜色对话框/剪切版操作等等控件用法以及记事本菜单事件/按键事件的具体代码)
- C#中创建、打开、读取、写入、保存Excel的一般性代码
- c# 对话框:打开对话框 保存文件对话框 设置字体及颜色对话框
- C#中创建、打开、读取、写入、保存Excel的一般性代码
- 一个WinForm记事本程序(包含主/下拉/弹出菜单/打开文件/保存文件/打印/页面设置/字体/颜色对话框/剪切版操作等等控件用法以及记事本菜单事件/按键事件的具体代码)
- 以下是关于对称加密算法的C#实现代码,大家可以根据需要更改不同的算法,文中以Rijndael算法为例
- C#中创建、打开、读取、写入、保存Excel的一般性代码
- C#中创建、打开、读取、写入、保存Excel的一般性代码