该程序是通过WinForm通过C#创建一个类似于文本编辑器一样的东西,可以通过菜单和状态栏来改变字体是否字体,是否是粗体,斜体.下划线等等 ....
1.界面就是一个MENU控件,一个TOOLSTRIP控件.注意的是要实现CHECKedCHANG功能,那么就要把他们属性.,checkonchange设置为true;
2. 各个按纽改变时的控件程序:
//
用Button设置粗体
private void toolStripButton1_CheckedChanged( object sender, EventArgs e)
{
Font oldFont;
Font newFont;
oldFont = richTextBox1.SelectionFont;
//得到当前按钮的状态,到底是checked状态还是没有checked的状态
bool checkStatse = ((ToolStripButton)sender).Checked;
if (!oldFont.Bold && checkStatse)
{
//设置新的字体
newFont = new Font(oldFont, oldFont.Style | FontStyle.Bold);
}
else
{
newFont = new Font(oldFont, oldFont.Style & ~FontStyle.Bold);
}
richTextBox1.SelectionFont = newFont;
richTextBox1.Focus();
}
// 用Button设置斜体
private void toolStripButton2_CheckedChanged( object sender, EventArgs e)
{
Font oldFont;
Font newFont;
oldFont = richTextBox1.SelectionFont;
bool checkStatse = ((ToolStripButton)sender).Checked;
if (!oldFont.Italic && checkStatse)
{
newFont = new Font(oldFont, oldFont.Style | FontStyle.Italic);
}
else
{
newFont = new Font(oldFont, oldFont.Style & ~FontStyle.Italic);
}
richTextBox1.SelectionFont = newFont;
richTextBox1.Focus();
}
// 用Button设置下划线
private void toolStripButton3_CheckedChanged( object sender, EventArgs e)
{
Font oldFont;
Font newFont;
oldFont = richTextBox1.SelectionFont;
bool checkStatse = ((ToolStripButton)sender).Checked;
if (!oldFont.Underline && checkStatse)
{
newFont = new Font(oldFont, oldFont.Style | FontStyle.Underline);
}
else
{
newFont = new Font(oldFont, oldFont.Style & ~FontStyle.Underline);
}
richTextBox1.SelectionFont = newFont;
richTextBox1.Focus();
}
private void boldToolStripMenuItem_CheckedChanged_1( object sender, EventArgs e)
{
//menu上边的设置按钮的checled与否,再根据checkchange来改变
toolStripButton1.Checked = boldToolStripMenuItem.Checked;
}
private void 下划线ToolStripMenuItem_CheckedChanged( object sender, EventArgs e)
{
toolStripButton3.Checked = 下划线ToolStripMenuItem.Checked;
}
private void 斜体ToolStripMenuItem_CheckedChanged_1( object sender, EventArgs e)
{
toolStripButton2.Checked = 斜体ToolStripMenuItem.Checked;
}
private void toolStripButton1_CheckedChanged( object sender, EventArgs e)
{
Font oldFont;
Font newFont;
oldFont = richTextBox1.SelectionFont;
//得到当前按钮的状态,到底是checked状态还是没有checked的状态
bool checkStatse = ((ToolStripButton)sender).Checked;
if (!oldFont.Bold && checkStatse)
{
//设置新的字体
newFont = new Font(oldFont, oldFont.Style | FontStyle.Bold);
}
else
{
newFont = new Font(oldFont, oldFont.Style & ~FontStyle.Bold);
}
richTextBox1.SelectionFont = newFont;
richTextBox1.Focus();
}
// 用Button设置斜体
private void toolStripButton2_CheckedChanged( object sender, EventArgs e)
{
Font oldFont;
Font newFont;
oldFont = richTextBox1.SelectionFont;
bool checkStatse = ((ToolStripButton)sender).Checked;
if (!oldFont.Italic && checkStatse)
{
newFont = new Font(oldFont, oldFont.Style | FontStyle.Italic);
}
else
{
newFont = new Font(oldFont, oldFont.Style & ~FontStyle.Italic);
}
richTextBox1.SelectionFont = newFont;
richTextBox1.Focus();
}
// 用Button设置下划线
private void toolStripButton3_CheckedChanged( object sender, EventArgs e)
{
Font oldFont;
Font newFont;
oldFont = richTextBox1.SelectionFont;
bool checkStatse = ((ToolStripButton)sender).Checked;
if (!oldFont.Underline && checkStatse)
{
newFont = new Font(oldFont, oldFont.Style | FontStyle.Underline);
}
else
{
newFont = new Font(oldFont, oldFont.Style & ~FontStyle.Underline);
}
richTextBox1.SelectionFont = newFont;
richTextBox1.Focus();
}
private void boldToolStripMenuItem_CheckedChanged_1( object sender, EventArgs e)
{
//menu上边的设置按钮的checled与否,再根据checkchange来改变
toolStripButton1.Checked = boldToolStripMenuItem.Checked;
}
private void 下划线ToolStripMenuItem_CheckedChanged( object sender, EventArgs e)
{
toolStripButton3.Checked = 下划线ToolStripMenuItem.Checked;
}
private void 斜体ToolStripMenuItem_CheckedChanged_1( object sender, EventArgs e)
{
toolStripButton2.Checked = 斜体ToolStripMenuItem.Checked;
}
3.下拉式选单选择字体:
private
void
toolStripComboBox1_SelectedIndexChanged(
object
sender, EventArgs e)
{
string str = ((ToolStripComboBox)sender).SelectedItem.ToString();
Font newFont = new Font(str, 30, richTextBox1.SelectionFont.Style);
richTextBox1.SelectionFont = newFont;
}
{
string str = ((ToolStripComboBox)sender).SelectedItem.ToString();
Font newFont = new Font(str, 30, richTextBox1.SelectionFont.Style);
richTextBox1.SelectionFont = newFont;
}
3.另外,皮肤的设置是通过使用了主题控件DLL,然后直接调用实现的:
private
void
blueToolStripMenuItem_Click(
object
sender, EventArgs e)
{
//设置皮肤
skinEngine1.SkinFile = "DiamondBlue.ssk";
}
{
//设置皮肤
skinEngine1.SkinFile = "DiamondBlue.ssk";
}