How to set SelectionFont when it returns null?
-
Hi there, I've got a standard RTF control and am coding a basic text formatter. In the event the user selects a section of text which has multiple fonts contained in it, SelectionFont will return null - that's documented and accepted behaviour. However - how do I now set the font for the selected text to the new font in that case? All the examples I've found use variations on the theme of: richTextBox1.SelectionFont = new Font( currentFont.FontFamily, currentFont.Size, newFontStyle); which clearly won't work if richTextBox1.SelectionFont == null. Please help! Kind regards, John.
-
Hi there, I've got a standard RTF control and am coding a basic text formatter. In the event the user selects a section of text which has multiple fonts contained in it, SelectionFont will return null - that's documented and accepted behaviour. However - how do I now set the font for the selected text to the new font in that case? All the examples I've found use variations on the theme of: richTextBox1.SelectionFont = new Font( currentFont.FontFamily, currentFont.Size, newFontStyle); which clearly won't work if richTextBox1.SelectionFont == null. Please help! Kind regards, John.
Hi, you can set it to any font you like: rtb.SelectionFont=new Font("Arial", 24, FontStyle.Bold); if you want it to resemble the original font(s), you might: - remember the selection start and length - apply a new selection, inside the original one (e.g. the first char) so you can investigate what font that was using - maybe iterate the previous step for different selection parts - restore the original selection - now apply a new font, based on what you discovered :)
Luc Pattyn [My Articles] [Forum Guidelines]
-
Hi, you can set it to any font you like: rtb.SelectionFont=new Font("Arial", 24, FontStyle.Bold); if you want it to resemble the original font(s), you might: - remember the selection start and length - apply a new selection, inside the original one (e.g. the first char) so you can investigate what font that was using - maybe iterate the previous step for different selection parts - restore the original selection - now apply a new font, based on what you discovered :)
Luc Pattyn [My Articles] [Forum Guidelines]
-
Hi, you can set it to any font you like: rtb.SelectionFont=new Font("Arial", 24, FontStyle.Bold); if you want it to resemble the original font(s), you might: - remember the selection start and length - apply a new selection, inside the original one (e.g. the first char) so you can investigate what font that was using - maybe iterate the previous step for different selection parts - restore the original selection - now apply a new font, based on what you discovered :)
Luc Pattyn [My Articles] [Forum Guidelines]