[.net] Rich Text Box Font Size
-
Is there a way I can change only the font size of the contents in a Rich Text box? I've tried using
MainTxt.Font = New Font(MainTxt.Font.Name, 12)
but that still removes any bold, italics, etc. Any thoughts would be greatly appreciated. Thanks for your time, Brian
-
Is there a way I can change only the font size of the contents in a Rich Text box? I've tried using
MainTxt.Font = New Font(MainTxt.Font.Name, 12)
but that still removes any bold, italics, etc. Any thoughts would be greatly appreciated. Thanks for your time, Brian
If you go in to the design view of the form and go in to the property of the rich text box. You can set the font size under Font property. Or you can set the font size in the load method of that form. by:
RichTextBox1.Font = New Font(RichTextBox1.Font.Name, 5)
--------------------------------- There is life outside coding.
-
If you go in to the design view of the form and go in to the property of the rich text box. You can set the font size under Font property. Or you can set the font size in the load method of that form. by:
RichTextBox1.Font = New Font(RichTextBox1.Font.Name, 5)
--------------------------------- There is life outside coding.
-
The problem with that is the contents of the Rich Text Box, an rtf file, is loaded and reloaded several times throughout the program.
Maybe you can first select all the text, and then change the selectionfont.
'Dunno if this works:
'select all text
rtb.SelectionText = rtb.Text
'change font (only size so use old font)
'i don't know what happens if there are different fonts involved in the selection..
rtb.SelectionFont = New Font(rtb.SelectionFont, 12.0!)
'deselect the text
rtb.SelectionLength = 0You could also look at the RichTextBoxExtended article.
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.." -- Mark McCormick
|| Fold With Us! || Pensieve || VG.Net ||
-
Maybe you can first select all the text, and then change the selectionfont.
'Dunno if this works:
'select all text
rtb.SelectionText = rtb.Text
'change font (only size so use old font)
'i don't know what happens if there are different fonts involved in the selection..
rtb.SelectionFont = New Font(rtb.SelectionFont, 12.0!)
'deselect the text
rtb.SelectionLength = 0You could also look at the RichTextBoxExtended article.
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.." -- Mark McCormick
|| Fold With Us! || Pensieve || VG.Net ||
-
Crap. You could do it one char at a time, but i think it's going to be slooooooow. I'm going to bed now, good luck with it :rose:
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.." -- Mark McCormick
|| Fold With Us! || Pensieve || VG.Net ||
-
Using just the standard RTB control, you'll have to go through each part of the text and see if the font changes from the previous font style. Say you have a length of text and only the middle 1/3 of the text is in a different style. You'd have to do 3 font changes. Select the first part of the text, change it's font size by creating a new font using the name and styles of the existing font. Then find the next section of text based on its Font, change it's font, then find the last section of text and do the same. Not very efficient, huh? Your only alternative is to replace the RTB with an extended version of the control that offers, well, more control over the editing capability of the text.
Dave Kreskowiak Microsoft MVP - Visual Basic
-
Crap. You could do it one char at a time, but i think it's going to be slooooooow. I'm going to bed now, good luck with it :rose:
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.." -- Mark McCormick
|| Fold With Us! || Pensieve || VG.Net ||
Yeah it is!! :-D The way to do it, without the RTB is to represent the Text and formatting in a data structure behind the scenes, then render the visible version using that data. It then makes changing the font, or pieces of it, in sections very easy since you're not hunting for the changes in the font through out the text. The code would already know where to make the changes.
Dave Kreskowiak Microsoft MVP - Visual Basic
-
Yeah it is!! :-D The way to do it, without the RTB is to represent the Text and formatting in a data structure behind the scenes, then render the visible version using that data. It then makes changing the font, or pieces of it, in sections very easy since you're not hunting for the changes in the font through out the text. The code would already know where to make the changes.
Dave Kreskowiak Microsoft MVP - Visual Basic
-
I haven't written anything like that. I just have a couple theories in my head about how I would approach the problem. Storing the text seperate from the formatting gives you quick access to the formatting itself. Pointers between text segments and existing formatting objects in a collection would allow for reuse of the same formatting object to control the formatting of several segments of text.
Dave Kreskowiak Microsoft MVP - Visual Basic