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. Text Width

Text Width

Scheduled Pinned Locked Moved C#
tutorialquestion
3 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.
  • A Offline
    A Offline
    Andrew Peace
    wrote on last edited by
    #1

    Hi, Does anyone know how to retrieve the width of a string if outputted to the screen in a given font, e.g. Arial 12 and the string "Hello World"? In other words, how many pixels wide would that string (or any given string) be on the screen? Thanks! -- Andrew.

    J 1 Reply Last reply
    0
    • A Andrew Peace

      Hi, Does anyone know how to retrieve the width of a string if outputted to the screen in a given font, e.g. Arial 12 and the string "Hello World"? In other words, how many pixels wide would that string (or any given string) be on the screen? Thanks! -- Andrew.

      J Offline
      J Offline
      James T Johnson
      wrote on last edited by
      #2

      The graphics object has a MeasureString method which returns the size of the text. You pass in the string and the font object to measure with. There are a few other parameters that can be used to adjust how the text will be rendered (the StringFormat class). James Simplicity Rules!

      A 1 Reply Last reply
      0
      • J James T Johnson

        The graphics object has a MeasureString method which returns the size of the text. You pass in the string and the font object to measure with. There are a few other parameters that can be used to adjust how the text will be rendered (the StringFormat class). James Simplicity Rules!

        A Offline
        A Offline
        Andrew Peace
        wrote on last edited by
        #3

        Thanks mate! Just what I needed :). Now just what I need is some sleep :-D! Thanks again, -- Andrew.

        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