【发布时间】:2015-10-27 09:04:00
【问题描述】:
我想要一个 RichTextEditor 控件,它具有所有的编辑选项,如 BOLD、ITALIC、STYLE、FONT... 我想在编辑器的内容将是 Outlook 邮件正文(Outlook 2013)的 Winform 中使用它,即它应该支持所有富文本、图像等。
在 VS 2012 中,我们无法控制这种类型!!!
【问题讨论】:
标签: c# winforms rich-text-editor outlook-2013
我想要一个 RichTextEditor 控件,它具有所有的编辑选项,如 BOLD、ITALIC、STYLE、FONT... 我想在编辑器的内容将是 Outlook 邮件正文(Outlook 2013)的 Winform 中使用它,即它应该支持所有富文本、图像等。
在 VS 2012 中,我们无法控制这种类型!!!
【问题讨论】:
标签: c# winforms rich-text-editor outlook-2013
RichTextBox 确实有这些选项。只需将格式化的文本粘贴到其中即可查看。
当然,没有OutlookNewMessageWithFormattingControlsForm,你必须实现你的粗体、斜体等按钮/菜单项背后的功能。
请参见下面的示例。 btnBold 是 CheckBox 和 Appearance.Button,menuItemBold 是 ToolStripMenuItem。
private bool isAdjusting;
private void richTextBox1_SelectionChanged(object sender, EventArgs e)
{
if (richTextBox1.SelectionFont == null)
return;
bool isBold = (richTextBox1.SelectionFont.Style & FontStyle.Bold) == FontStyle.Bold;
isAdjusting = true;
btnBold.Checked = isBold;
menuItemBold.Checked = isBold;
isAdjusting = false;
}
private void btnBold_CheckedChanged(object sender, EventArgs e)
{
if (isAdjusting)
return;
SetBold(btnBold.Checked);
}
private void SetBold(bool bold)
{
if (richTextBox1.SelectionFont == null)
return;
FontStyle style = richTextBox1.SelectionFont.Style;
style = bold ? style | FontStyle.Bold : style & ~FontStyle.Bold;
richTextBox1.SelectionFont = new Font(richTextBox1.SelectionFont, style);
}
【讨论】:
Ctrl+B。