Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Hi All,

I am having a trouble in RichTextBox Control in Windows application,I have three buttons bold,underlined and Italics for the RichTextBox.I am selecting a sentence which is partially regular and partially bold . After selecting that sentence , i am trying to convert the selected sentence into italics , the below code is not giving me the expected output . please help me to fix this issue .

 

 

Note: 'rtfRichText' is RichTextBox

private void btnBold_Click(object sender, EventArgs e)
{
FontStyle style = rtfRichText.SelectionFont.Style;
if (rtfRichText.SelectionFont.Bold)
{
style &= ~FontStyle.Bold;
}
else
{
style |= FontStyle.Bold;
}
rtfRichText.SelectionFont = new Font(rtfRichText.SelectionFont, style);

}

private void btnItalic_Click(object sender, EventArgs e)
{
FontStyle style = rtfRichText.SelectionFont.Style;
FontFamily style2 = rtfRichText.SelectionFont.FontFamily;

if (rtfRichText.SelectionFont.Italic)
{
style &= ~FontStyle.Italic;
}
else
{
style |= FontStyle.Italic;
}
rtfRichText.SelectionFont = new Font(rtfRichText.SelectionFont, style);
}

private void btnUnderLine_Click(object sender, EventArgs e)
{
FontStyle style = rtfRichText.SelectionFont.Style;
if (rtfRichText.SelectionFont.Underline)
{
style &= ~FontStyle.Underline;
}
else
{
style |= FontStyle.Underline;
}
rtfRichText.SelectionFont = new Font(rtfRichText.SelectionFont, style);
}

 

Thanks and Regards,

 

Faizal Ahmed.H

Edited by PlausiblyDamp

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...