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. subscript text

subscript text

Scheduled Pinned Locked Moved C#
tutorialquestion
2 Posts 2 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.
  • S Offline
    S Offline
    Stefan Troschuetz
    wrote on last edited by
    #1

    Hi! Is it possible to format a string so that a certain part will be displayed as subscript text? For example a label displays the string "n1 + n2 =" and "1" and "2" should be subscript. I searched through the documentation but must have missed it, at least i hope so ;) THX in advance

    H 1 Reply Last reply
    0
    • S Stefan Troschuetz

      Hi! Is it possible to format a string so that a certain part will be displayed as subscript text? For example a label displays the string "n1 + n2 =" and "1" and "2" should be subscript. I searched through the documentation but must have missed it, at least i hope so ;) THX in advance

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      There are several ways. One is through markup like with HTML that uses the <sup> and <sub> tags. I doubt that's appropriate here, however. Another is to get a font that is full of these. It's not uncommon to have a font represent symbols. Microsoft uses several fonts for glyphs in Outlook and other applications. Since .NET supports Unicode, there is the superscript and subscript diacritics in the U+2070 through U+209F range. The problem is that you need a font that supports them. Tahoma (default font) and Arial Unicode MS currently do not, nor do any of the other common ones. If you had a font that supported this Unicode range and displayed the text in a TextBox (for example), then you could use:

      "n\u2081 + n\u2082 ="

      Finally, about your only other option is to owner-draw the text yourself in parts using Graphics.DrawString and either off-setting the coordinates of the upper-left corner or using a StringFormat with a LineAlignment set accordingly.

      Microsoft MVP, Visual C# My Articles

      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