富文本编辑器控件与WinForms的编辑选项

时间:2015-10-27 09:04:01

标签: c# winforms rich-text-editor outlook-2013

我希望有一个RichTextEditor控件,它将具有BOLD,ITALIC,STYLE,FONT等所有编辑选项... 我想在winform中使用它,其中编辑器的内容将是Outlook邮件正文(Outlook 2013),即它应该支持所有富文本,图像等。

在VS 2012中,我们没有这种类型的任何控制!!!

任何链接或代码都会有效。 感谢

2 个答案:

答案 0 :(得分:1)

RichTextBox确实有这些选项。只需将带格式的文本粘贴到其中即可查看。

当然,没有OutlookNewMessageWithFormattingControlsForm,你必须实现BOLD,ITALIC等按钮/菜单项背后的功能。

请参阅下面的示例。 btnBoldCheckBox Appearance.ButtonmenuItemBoldToolStripMenuItem

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);
}

答案 1 :(得分:0)

您可以使用https://github.com/dcsoft-yyf/CSharpWriter,就像RichTextBox,但是可以通过GDI +绘制文档视图。它包含一个DOM,您可以更改DOM元素以更改内容的样式。它是由C#2.0编写的,因此您可以在VS.NET2005到VS2019中使用它。

相关问题