contextmenustripform.cs
来自「csharp课本的源代码」· CS 代码 · 共 67 行
CS
67 行
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace ContextMenuStripExample
{
public partial class ContextMenuStripForm : Form
{
// 这些变量分别用于保存richTextBox1中初始文本的字体设置
//FontFamily oldFontFamily=richTextBox1.SelectionFont.FontFamily;
Color oldColor;
int smallsize=4;
FontStyle oldFontStyle;
public ContextMenuStripForm()
{
InitializeComponent();
}
private void toolStripMenuItem大字体_Click(object sender, EventArgs e)
{
FontFamily oldFontFamily = richTextBox1.SelectionFont.FontFamily;
richTextBox1.SelectionFont = new Font(oldFontFamily, 24, oldFontStyle);
}
private void toolStripMenuItem小字体_Click(object sender, EventArgs e)
{
FontFamily oldFontFamily = richTextBox1.SelectionFont.FontFamily;
richTextBox1.SelectionFont = new Font(oldFontFamily, smallsize, oldFontStyle);
}
private void toolStripMenuItem红色字体_Click(object sender, EventArgs e)
{
richTextBox1.SelectionColor = Color.Red;
}
private void toolStripMenuItem蓝色字体_Click(object sender, EventArgs e)
{
richTextBox1.SelectionColor = Color.Blue;
}
private void toolStripMenuItem绿色字体_Click(object sender, EventArgs e)
{
richTextBox1.SelectionColor = Color.Green;
}
private void toolStripMenuItem恢复字体大小_Click(object sender, EventArgs e)
{
FontFamily oldFontFamily = richTextBox1.SelectionFont.FontFamily;
richTextBox1.SelectionFont = new Font(oldFontFamily, 8, oldFontStyle);
}
private void toolStripMenuItem恢复字体颜色_Click(object sender, EventArgs e)
{
richTextBox1.SelectionColor = oldColor;
}
private void toolStripMenuItem保存文件_Click(object sender, EventArgs e)
{
richTextBox1.SaveFile("D:\\source.rtf", RichTextBoxStreamType.RichText);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?