Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. [.net] Rich Text Box Font Size

[.net] Rich Text Box Font Size

Scheduled Pinned Locked Moved Visual Basic
csharpquestiondiscussion
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bamnet
    wrote on last edited by
    #1

    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

    E 1 Reply Last reply
    0
    • B bamnet

      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

      E Offline
      E Offline
      EvoFreak
      wrote on last edited by
      #2

      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.

      B 1 Reply Last reply
      0
      • E EvoFreak

        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.

        B Offline
        B Offline
        bamnet
        wrote on last edited by
        #3

        The problem with that is the contents of the Rich Text Box, an rtf file, is loaded and reloaded several times throughout the program.

        M 1 Reply Last reply
        0
        • B bamnet

          The problem with that is the contents of the Rich Text Box, an rtf file, is loaded and reloaded several times throughout the program.

          M Offline
          M Offline
          Marc 0
          wrote on last edited by
          #4

          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 = 0

          You 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 ||

          B 1 Reply Last reply
          0
          • M Marc 0

            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 = 0

            You 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 ||

            B Offline
            B Offline
            bamnet
            wrote on last edited by
            #5

            Same thing, lost the bold and styles.

            M D 2 Replies Last reply
            0
            • B bamnet

              Same thing, lost the bold and styles.

              M Offline
              M Offline
              Marc 0
              wrote on last edited by
              #6

              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 ||

              D 1 Reply Last reply
              0
              • B bamnet

                Same thing, lost the bold and styles.

                D Offline
                D Offline
                Dave Kreskowiak
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                • M Marc 0

                  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 ||

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #8

                  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

                  B 1 Reply Last reply
                  0
                  • D Dave Kreskowiak

                    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

                    B Offline
                    B Offline
                    bamnet
                    wrote on last edited by
                    #9

                    Now how would this translate into some hard code?

                    D 1 Reply Last reply
                    0
                    • B bamnet

                      Now how would this translate into some hard code?

                      D Offline
                      D Offline
                      Dave Kreskowiak
                      wrote on last edited by
                      #10

                      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

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups