0
votes

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) i.e it should support all rich text,image etc.

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

1

1 Answers

1
votes

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