CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2000
    Location
    AP,INDIA
    Posts
    13

    How to catch the length of string in pixels

    hello all,

    i have got a doubt. Can any one help me
    how to catch the length of a string in pixel.

    For example i want to draw an image after printing
    a string like this

    "HEllo how are you" <Image>

    "Hai fine how about you are you ok" <Image>

    Can any one tell me a general approach for this

    Thanx in advance
    k_venkurao


  2. #2
    Join Date
    Jan 2000
    Location
    Canada
    Posts
    249

    Re: How to catch the length of string in pixels

    You can use the FontMetrics class to get the length of a string in pixels. You can do this by the following:

    FontMetrics metrics = aWindow.getFontMetrics(); // aWindow is a frame
    int stringLength = metrics.stringLength( myString );

    -------------------------------------------
    weaver
    icq# 64665116
    Please rate this post.
    http://weaver.x7.htmlplanet.com

  3. #3
    Join Date
    May 2000
    Location
    AP,INDIA
    Posts
    13

    Re: How to catch the length of string in pixels

    Thank you very much for you reply. Can you tell the same for an applet. Because i have developed a chat server. I will to give an option for images
    also.

    Thankyou very much
    k_venkurao


  4. #4
    Join Date
    Jan 2000
    Location
    Canada
    Posts
    249

    Re: How to catch the length of string in pixels

    Ok, here's a version that should work with applets.

    Graphics g = getGraphics();
    FontMetrics fm = g.getFontMetrics();
    int length = fm.stringLength(myString);

    -------------------------------------------
    weaver
    icq# 64665116
    Please rate this post.
    http://weaver.x7.htmlplanet.com

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

Featured