GettextExtentExPoint (coredll)
Last changed: -129.188.33.26

.
Summary
This function retrieves the number of characters in a specified string that fit within a specified space and fills an array with the text extent for each of those characters. A text extent is the distance between the beginning of the space and a character that fits in the space.

C# Signature:

    [DllImport("coredll.dll")]
    public static extern bool GetTextExtentExPointW(IntPtr hDc, string lpString, int nLength, int nMaxExtent, int[] lpnFit, int[] alpDx, out Size size);

User-Defined Types:

None.

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

None.

Tips & Tricks:

Set lpnFit to null to ignore nMaxExtent.

Setting lpnFit and alpDx to null will get you the functionality of GetTextExtentPoint.

Sample Code:

    ...

    using(Graphics g = ctrl.CreateGraphics())
    {
        IntPtr hDC = g.GetHdc();
        string testString = "Hello p/Invoke";
        int width = 30;
        int[] fi = new int[1];
        int[] charExtents = new int[testString.Length];
        Size sz;

        GetTextExtentExPointW(hDC, testString, testString.Length, width, fit, charExtents, out sz);

        ...

        g.ReleaseHdc(hDC);
    }

    ...

Please add some!

Documentation