Results 1 to 4 of 4

Thread: How to calc exactly length in pixel unit of any string

  1. #1
    AngelFire
    Guest

    How to calc exactly length in pixel unit of any string

    Hello u guys!

    Do u know how to calc exactly length in pixel unit of any given string? I tried to use GetCharWidth and GetTextMetrics but can not get exactly length of string.

  2. #2
    Frenzied Member
    Join Date
    Aug 2001
    Posts
    1,075
    You can use the TextWidth method of a Form or Picture box provided the ScaleMode is vbPixels. If you want to get the Width of text in a label or something just make sure the Font name, size, etc are the same for the form and what ever other object you are trying to get the text width for.

    VB Code:
    1. Me.ScaleMode = vbTwips
    2. Debug.Print Me.TextWidth("Hello world")
    3. Me.ScaleMode = vbPixels
    4. Debug.Print Me.TextWidth("Hello world")

    Greg
    Free VB Add-In - The Reference Librarian
    Click Here for screen shot and download link.

  3. #3
    Also...
    VB Code:
    1. Me.Font.Name = "Arial"
    2. Me.Font.Size = 12
    3. .
    4. .
    5. .

  4. #4
    AngelFire
    Guest
    Originally posted by gdebacker
    You can use the TextWidth method of a Form or Picture box provided the ScaleMode is vbPixels. If you want to get the Width of text in a label or something just make sure the Font name, size, etc are the same for the form and what ever other object you are trying to get the text width for.

    VB Code:
    1. Me.ScaleMode = vbTwips
    2. Debug.Print Me.TextWidth("Hello world")
    3. Me.ScaleMode = vbPixels
    4. Debug.Print Me.TextWidth("Hello world")

    Greg

    Yeah, it seem to be good for me. Thanks for ur help.

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