none
The correct way to measure a strings width? RRS feed

  • Question

  • Im trying to code a method that will truncate a text, if it doesn´t fit in the rectangle that is given as an argument to DrawString.
    The problem is that measure string doesn´t seem to give the correct width.

    I found this article: http://www.syncfusion.com/faq/windowsforms/faq_c39c.aspx#q763q

    Is this true for measure string in Compact Framework? If so, how do you work around it, since MeasureString doesn´t have any overloads in Compact Framework?
    Thursday, September 18, 2008 3:22 PM

Answers

  • Hi

     

    There were several cases someone facing this problem which was workarounded by specifying a StringFormat argument for Graphics..::.MeasureString Method.

     

    Since it’s not available in the .NET CF, could you be more specific on what happened and how it caused any inconvenience to you?

     

    Still you may try P/Invoke the DrawText function to measure string. More details can be found here:
    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3694042&SiteID=1

     

    Regards

    Chunsheng Tang

     

    Monday, September 22, 2008 4:21 AM
    Moderator