faizal_h Posted September 18, 2008 Posted September 18, 2008 (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 September 18, 2008 by PlausiblyDamp Quote
Administrators PlausiblyDamp Posted September 18, 2008 Administrators Posted September 18, 2008 The problem is down to the fact the selected text doesn't have a single font - at a guess you might have to loop over every character and set it's font individually... Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.