简体   繁体   中英

Rich Text Editor control with edit option for WinForms

I want to have a RichTextEditor control which will have all the editing option like BOLD, ITALIC, STYLE, FONT... I want to use it in a winform where the content of the editor will be an Outlook mail body (Outlook 2013) ie it should support all rich text,image etc.

In VS 2012 we don't have any control of this type !!!

RichTextBox does have these options. Just paste a formatted text into it to see it.

Of course, there is no OutlookNewMessageWithFormattingControlsForm , you have to implement the functionality behind your BOLD, ITALIC, etc. buttons/menu items.

See the example below. btnBold is a CheckBox with Appearance.Button , menuItemBold is a 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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM