Page 1 of 1
Messing With Text in a RichTextBox
Posted: Tue Aug 03, 2010 5:17 pm
by GoodGuy17
Hello,
I need help doing this:
I am making a CodePad(source viewer), it has tabs, and I want the text size in the RichTextBoxes to be bigger. How do I do so? I tried:
CType(TabControl1.SelectedTab.Controls.Item(0), RichTextBox).Font.Size = 12
Error using that code: Font.Size is read-only. I can't write it's value, I can only check it's value.
Re: Messing With Text in a RichTextBox
Posted: Tue Aug 03, 2010 8:36 pm
by mandai
Is control 0 of that tab always a richtextbox?
Try this:
Code: Select all Dim fsindex As Integer = RichTextBox1.SelectedRtf.IndexOf("\fs")
If fsindex = -1 Then
MsgBox("no fontsize found in selected rtf")
Return
End If
Dim test As String = RichTextBox1.SelectedRtf.Remove(fsindex + 3, RichTextBox1.SelectedRtf.IndexOf(" "c, fsindex) - fsindex - 3)
RichTextBox1.SelectedRtf = test.Insert(fsindex + 3, "88")
You might also want to check out the RTF specification at
http://www.biblioscape.com/rtf15_spec.htm
Re: Messing With Text in a RichTextBox
Posted: Tue Aug 03, 2010 8:48 pm
by GoodGuy17
Yes, it is the only control that can ever possibly be in the tab.
Re: Messing With Text in a RichTextBox
Posted: Tue Aug 03, 2010 9:05 pm
by mandai
Ok, I just posted an example that changes the font size of the selected rtf text.
Re: Messing With Text in a RichTextBox
Posted: Tue Aug 03, 2010 9:12 pm
by GoodGuy17
No, I need the code to make the font size the richtextboxes bigger when I make new ones.
I have tabs, each tab has a richtextbox, I want, as soon as the richtextbox is put in the tab, its fontsize to be bigger, so it will be easier to read.
Re: Messing With Text in a RichTextBox
Posted: Tue Aug 03, 2010 9:20 pm
by mandai
You could always use the Rtf property instead of SelectedRtf if it has to be applied to the whole document.
Re: Messing With Text in a RichTextBox
Posted: Tue Aug 03, 2010 9:27 pm
by GoodGuy17
So if I am using
Dim SCode As New RichTextBox
TabControl1.TabPages.Add(1, "Form " & i & ".vb")
TabControl1.SelectTab(i - 1)
SCode.Name = "TE"
SCode.Dock = DockStyle.Fill
SCode.ContextMenuStrip = ContextMenuStrip1
TabControl1.SelectedTab.Controls.Add(SCode)
i = i + 1
I put SCode.Rtf = "12"???
I want to make the size of the text in the created RichTextBox larger than it is when this event is called. Not change the richtextfile.
Re: Messing With Text in a RichTextBox
Posted: Tue Aug 03, 2010 10:30 pm
by mandai
Oh ok if you don't want to change the RTF you can change the font property this way:
Code: Select allRichTextBox1.Font = New Font(FontFamily.GenericMonospace, 40, FontStyle.Regular, GraphicsUnit.Pixel)
Re: Messing With Text in a RichTextBox
Posted: Wed Aug 04, 2010 8:37 pm
by GoodGuy17
This worked! Thanks! I will put you in my cool credits window.