Results 1 to 5 of 5

Thread: [RESOLVED] Measure the height of a string with a FIXED max width

  1. #1

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    Resolved [RESOLVED] Measure the height of a string with a FIXED max width

    Ok - this is what I was wondering just say I have a string as follows:

    Code:
    This is a long long 
    lojngoi
    sudofi usdfh ksjdhfjk sdhfgkj shgh sdfhg sdfg sdfgdsfg
    ... I want to specify a maximum width (eg 180) for my string and get the height returned... the picture below explains in more detail:

    Thanks
    Kris
    Attached Images Attached Images  

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Measure the height of a string with a FIXED max width

    Can't you use a textbox with Multiline = true for that?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Measure the height of a string with a FIXED max width

    vb.net Code:
    1. Dim size = myGraphics.MeasureString(myString, myFont, maxWidth)
    2. Dim height = size.Height
    Note that MeasureString returns a SizeF, not a Size, so in this case 'height' will be a Single, not an Integer.
    Last edited by jmcilhinney; Aug 26th, 2009 at 02:39 AM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    Re: [RESOLVED] Measure the height of a string with a FIXED max width

    dee-u - not a textbox

    jmcilhinney - thanks have used the measure string alot ... just didnt realise you could enter a max with - thanks

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] Measure the height of a string with a FIXED max width

    Quote Originally Posted by i00 View Post
    dee-u - not a textbox

    jmcilhinney - thanks have used the measure string alot ... just didnt realise you could enter a max with - thanks
    Which is why you read the documentation. I've pretty much never used MeasureString but I was aware of its existence and, when I read your question, it sounded like the obvious choice. I opened my MSDN Library and looked it up. If I could do that then you really should been able to as well, having more experience with MeasureString than I.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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