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. Is this possible?

Is this possible?

Scheduled Pinned Locked Moved Visual Basic
csharpquestion
5 Posts 3 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.
  • H Offline
    H Offline
    hansoctantan
    wrote on last edited by
    #1

    In VB.Net Any Text Control (TextBox, RichTextBox, etc...) Is it possible to bold a highlighted/particular text in a control? Thanks...

    I did't do that...

    W L 2 Replies Last reply
    0
    • H hansoctantan

      In VB.Net Any Text Control (TextBox, RichTextBox, etc...) Is it possible to bold a highlighted/particular text in a control? Thanks...

      I did't do that...

      W Offline
      W Offline
      Wayne Gaylard
      wrote on last edited by
      #2

      With a TextBox, you can only set the font and fontweight for the whole string. With the RichTextBox you can set any amount of fonts and font weights to your hearts desire. To set the current selected text to bold, or if it is already bold, set it to normal, you can use something like this :

      With Me.rtb
      If .SelectionFont IsNot Nothing Then
      Dim currentFont As System.Drawing.Font = .SelectionFont
      Dim newFontStyle As System.Drawing.FontStyle

              If .SelectionFont.Bold = True Then
                  newFontStyle = currentFont.Style - Drawing.FontStyle.Bold
              Else
                  newFontStyle = currentFont.Style + Drawing.FontStyle.Bold
              End If
      
              .SelectionFont = New Drawing.Font(currentFont.FontFamily, currentFont.Size, newFontStyle)
          End If
      End With
      

      Hope this helps

      Everyone dies - but not everyone lives

      H 1 Reply Last reply
      0
      • H hansoctantan

        In VB.Net Any Text Control (TextBox, RichTextBox, etc...) Is it possible to bold a highlighted/particular text in a control? Thanks...

        I did't do that...

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        hansoctantan wrote:

        Any Text Control (TextBox, RichTextBox, etc...)
        Is it possible to bold a highlighted/particular text in a control?

        No. You'd have to paint that part yourself.

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

        1 Reply Last reply
        0
        • W Wayne Gaylard

          With a TextBox, you can only set the font and fontweight for the whole string. With the RichTextBox you can set any amount of fonts and font weights to your hearts desire. To set the current selected text to bold, or if it is already bold, set it to normal, you can use something like this :

          With Me.rtb
          If .SelectionFont IsNot Nothing Then
          Dim currentFont As System.Drawing.Font = .SelectionFont
          Dim newFontStyle As System.Drawing.FontStyle

                  If .SelectionFont.Bold = True Then
                      newFontStyle = currentFont.Style - Drawing.FontStyle.Bold
                  Else
                      newFontStyle = currentFont.Style + Drawing.FontStyle.Bold
                  End If
          
                  .SelectionFont = New Drawing.Font(currentFont.FontFamily, currentFont.Size, newFontStyle)
              End If
          End With
          

          Hope this helps

          Everyone dies - but not everyone lives

          H Offline
          H Offline
          hansoctantan
          wrote on last edited by
          #4

          Thanks a lot, your code works perfectly...

          I did't do that...

          W 1 Reply Last reply
          0
          • H hansoctantan

            Thanks a lot, your code works perfectly...

            I did't do that...

            W Offline
            W Offline
            Wayne Gaylard
            wrote on last edited by
            #5

            Glad to help.

            Everyone dies - but not everyone lives

            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