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
Thanks and Regards,
Faizal Ahmed.H
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
C#:
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
Last edited by a moderator: