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. C#
  4. How to set diffrent words in a label with diffrent fonts

How to set diffrent words in a label with diffrent fonts

Scheduled Pinned Locked Moved C#
htmltutorial
3 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.
  • R Offline
    R Offline
    Roggey
    wrote on last edited by
    #1

    Hello I'm using System.Windows.Forms.Label and I want to add some text, where one or more words are bold or italic. I tried it with html tags but does not work. Somewhere i did read it should be done by html tags. I did it like this: label1.Text="my <b>test</b> string"; In the output i can see the html tags.< I hope someone can tell me how to do this. Thanks Roggey

    D K 2 Replies Last reply
    0
    • R Roggey

      Hello I'm using System.Windows.Forms.Label and I want to add some text, where one or more words are bold or italic. I tried it with html tags but does not work. Somewhere i did read it should be done by html tags. I did it like this: label1.Text="my <b>test</b> string"; In the output i can see the html tags.< I hope someone can tell me how to do this. Thanks Roggey

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

      Not supported by the label control. You'll either have to use multiple label controls for each word that is different (a messy solution), or come up with your own variant that supports it. The RichTextBox does support different fonts in the text stream, but is a rather heavyweight control to use as a label. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      1 Reply Last reply
      0
      • R Roggey

        Hello I'm using System.Windows.Forms.Label and I want to add some text, where one or more words are bold or italic. I tried it with html tags but does not work. Somewhere i did read it should be done by html tags. I did it like this: label1.Text="my <b>test</b> string"; In the output i can see the html tags.< I hope someone can tell me how to do this. Thanks Roggey

        K Offline
        K Offline
        keith maddox
        wrote on last edited by
        #3

        You can do just what you want in your paint method but you'll need to get a little more involved that you might want to. Basically what you need to do is paint the text of your control yourself. You'll notice that DrawString has a parameter for the font. Just use that and draw the string in sections, one for each font you are using. This also means that you'll need to use MeasureString for each piece as you draw it so you can get the next section to align to the proper place following the preceeding piece. Hope that makes sense.

        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