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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to find width and height of font object?

How to find width and height of font object?

Scheduled Pinned Locked Moved Visual Basic
questiongraphicsdesignhelptutorial
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.
  • K Offline
    K Offline
    Krishnaraj Barvathaya B
    wrote on last edited by
    #1

    Hi All, I am developing a windows based application where I am using System.Drawing.Printing.PrintDocument class for displaying report. I have provided design screen where user can change the font size and type. Now I am facing problem while printing. If I change the font size, I am loosing data and total information is not being displayed. Now my question is there any way to find out font width and height of the font object. Specifically not size. I know there is a method to find size. But its of no use to me. I need width and height separately. Thanks in advance, Regards, Krishnaraj

    D 1 Reply Last reply
    0
    • K Krishnaraj Barvathaya B

      Hi All, I am developing a windows based application where I am using System.Drawing.Printing.PrintDocument class for displaying report. I have provided design screen where user can change the font size and type. Now I am facing problem while printing. If I change the font size, I am loosing data and total information is not being displayed. Now my question is there any way to find out font width and height of the font object. Specifically not size. I know there is a method to find size. But its of no use to me. I need width and height separately. Thanks in advance, Regards, Krishnaraj

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

      There is no real height and width of a font object, since most fonts are not monospaced, there is no real character cell you can use to estimate how wide your string is. There's two ways to go about this. You actually have to use Graphics.MeasureString to get the dimensions of the drawn string to see how big it is in the supplied font. If it's too big, reduce the font size and try again. Keep doing so until the string fits. Or, I've found a second method that works in limited cases, but it's MUCH quicker if performance is an issue. Instead of drawing the string the exact size you need it, draw it to an offscreen bitmap in a MUCH larger font size, like 96 points. Then draw the bitmap in the control you want, scaled up/down to the size you need. If done properly, it draws nicely, without all the jaggies you get when scaling an image.

      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