【问题标题】:Rich Text Editor control with edit option for WinForms带有 WinForms 编辑选项的富文本编辑器控件
【发布时间】:2015-10-27 09:04:00
【问题描述】:

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

在 VS 2012 中,我们无法控制这种类型!!!

【问题讨论】:

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


    【解决方案1】:

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

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

    请参见下面的示例。 btnBoldCheckBoxAppearance.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);
    }
    

    【讨论】:

    • 感谢您的回复。我要问的是当邮件正文被复制到控制正文时,最终用户应该能够或可以选择做所有的样式,比如粗体、斜体、字体……就像我们在 MS-WORD 中一样!!!跨度>
    • 正如我所说,你应该实现这个功能。请参阅我编辑的答案。您还可以为菜单项分配热键,例如Ctrl+B
    • 网上也充满了完整的 WinForms 示例。仅仅为了使用另一个 3rd 方解决方案而切换到 WPF 没有任何意义。请参阅 TX Text Control 或 TE Edit,或 FireFX Editor,所有这些都是基于 WinForms 的专业编辑器。或者,这里是 DIY 版本的完整示例:codeproject.com/Articles/18356/… 无论是 WPF 还是 WinForms,您都无法避免使用基本 .NET 组件进行一些实现。
    猜你喜欢
    • 2011-01-06
    • 1970-01-01
    • 2011-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多