Mayank Jani

Mayank Jani

  • NA
  • 477
  • 73.5k

RichTextBox format with Bold, Underline & Font the same word

Jul 14 2018 8:42 AM
Dear Members,
 
I am working on a RichTextBox as letter printing format. I can format the letter with font, bold, italics etc. my problem is when I select a word or a string to apply bold and underline, it can apply only either bold or underline. after formating a paragraph, when I choose a word and select bold, then the word turns bold but the font gets changed!!
 
I use mouse right click to open menu and select option that I want to apply. Here is my code...
 
//For bold and italics
private void richTxtLetter_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
ContextMenu RightClick = new System.Windows.Forms.ContextMenu();

MenuItem MIbold = new MenuItem("Bold");
MIbold.Click += new EventHandler(BoldAction);
RightClick.MenuItems.Add(MIbold);

MenuItem MIitalics = new MenuItem("Italics");
MIitalics.Click += new EventHandler(ItalicsAction);
RightClick.MenuItems.Add(MIitalics);
 
richTxtLetter.ContextMenu = RightClick;
}
}
 
//Calling ...
void BoldAction(object sender, EventArgs e)
{
richTxtLetter.SelectionFont = new Font(richTxtLetter.Font, FontStyle.Bold);
}

void ItalicsAction(object sender, EventArgs e)
{
richTxtLetter.SelectionFont = new Font(richTxtLetter.Font, FontStyle.Italic);
}
 
Please let me know if there is any option that I can use bold and italics, or bold and underline to same word or string or paragraph. the font should remain the same as the whole letter created of.
 
Thank You
 
Mayank Jani

Answers (7)