Messing With Text in a RichTextBox

Do you need something made? then ask in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
9 posts Page 1 of 1
Contributors
GoodGuy17
Coding God
Coding God
Posts: 1610
Joined: Mon Sep 07, 2009 12:25 am

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.
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

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
Last edited by mandai on Tue Aug 03, 2010 9:01 pm, edited 2 times in total.
GoodGuy17
Coding God
Coding God
Posts: 1610
Joined: Mon Sep 07, 2009 12:25 am

Yes, it is the only control that can ever possibly be in the tab.
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Ok, I just posted an example that changes the font size of the selected rtf text.
GoodGuy17
Coding God
Coding God
Posts: 1610
Joined: Mon Sep 07, 2009 12:25 am

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.
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

You could always use the Rtf property instead of SelectedRtf if it has to be applied to the whole document.
GoodGuy17
Coding God
Coding God
Posts: 1610
Joined: Mon Sep 07, 2009 12:25 am

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.
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Oh ok if you don't want to change the RTF you can change the font property this way:
Code: Select all
RichTextBox1.Font = New Font(FontFamily.GenericMonospace, 40, FontStyle.Regular, GraphicsUnit.Pixel)
GoodGuy17
Coding God
Coding God
Posts: 1610
Joined: Mon Sep 07, 2009 12:25 am

This worked! Thanks! I will put you in my cool credits window.
9 posts Page 1 of 1
Return to “Tutorial Requests”