C#里面本身就自带有实现调节richtextbox控件字体大小的类,如下: C# code FontDialog fd = new FontDialog();//字体框 DialogResult d = fd.ShowDialog();//显示 if (d.Equals(DialogResult.OK)) { if (rich_Input.SelectedText.Length == 0)//如果未选定,那么就修改全部 rich_Input.Font = fd.Font; else //修改选定的文本 rich_Input.SelectionFont = fd.Font; }
下面是调整字体颜色的: ColorDialog MyDialog = new ColorDialog(); // Keeps the user from selecting a custom color. MyDialog.AllowFullOpen = false; // Allows the user to get help. (The default is false.) MyDialog.ShowHelp = true; // Sets the initial color select to the current text color. MyDialog.Color = rich_Input.ForeColor; // Update the text box color if the user clicks OK if (MyDialog.ShowDialog() == DialogResult.OK) rich_Input.ForeColor = MyDialog.Color;
Font oldFont = this.textbox1.SelectionFont FontStyle style = FontStyle.Regular; if (!oldFont.Underline) { style |= FontStyle.Underline; } if (!oldFont.Bold) { style |= FontStyle.Bold; } Font newFont = new Font(oldFont, style); this.textbox1.Font = newFont; 试试吧
C# code
FontDialog fd = new FontDialog();//字体框
DialogResult d = fd.ShowDialog();//显示
if (d.Equals(DialogResult.OK))
{
if (rich_Input.SelectedText.Length == 0)//如果未选定,那么就修改全部
rich_Input.Font = fd.Font;
else
//修改选定的文本
rich_Input.SelectionFont = fd.Font;
}
// Keeps the user from selecting a custom color.
MyDialog.AllowFullOpen = false;
// Allows the user to get help. (The default is false.)
MyDialog.ShowHelp = true;
// Sets the initial color select to the current text color.
MyDialog.Color = rich_Input.ForeColor; // Update the text box color if the user clicks OK
if (MyDialog.ShowDialog() == DialogResult.OK)
rich_Input.ForeColor = MyDialog.Color;
FontStyle style = FontStyle.Regular;
if (!oldFont.Underline)
{
style |= FontStyle.Underline;
}
if (!oldFont.Bold)
{
style |= FontStyle.Bold;
}
Font newFont = new Font(oldFont, style); this.textbox1.Font = newFont;
试试吧