Results 1 to 2 of 2

Thread: How to get char width and height

  1. #1

    Thread Starter
    Frenzied Member usamaalam's Avatar
    Join Date
    Nov 2002
    Location
    Karachi
    Posts
    1,308

    How to get char width and height

    Hello everybody,

    I need to display string which may be in different fonts and different sized. For positioning, I need to get the width of height of one character in pixels. If I have font name, font size etc. How can I calculate width and height of that particular character.

    Thanks

  2. #2
    Hyperactive Member Sgt-Peppa's Avatar
    Join Date
    Mar 2003
    Location
    Munich - Germany
    Posts
    476

    Re: How to get char width and height

    Code:
    System.Drawing.Graphics myGraphics = Graphics.FromHwnd(System.IntPtr.Zero); //new graphics object
    System.Drawing.SizeF mySize = myGraphics.MeasureString(myLabel.Text,myLabel.Font); //get the size of the text property
    myLabel.Width = (int)mySize.Width +1;
    a small Sample I used some time ago!

    Hope that helps!

    Stephan
    Keep Smiling - even if its hard
    Frankie Says Relax, wossname Says Yeah!
    wossname:--Currently I'm wearing a gimp suit and a parachute.
    C# - Base64 Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width