GetThemeTextExtent

[DllImport("uxtheme.dll", SetLastError = true)]
public static extern HRESULT GetThemeTextExtent(
   IntPtr hTheme,
   HDC hdc,
   int iPartId,
   int iStateId,
   [MarshalAs(UnmanagedType.LPWStr)] string pszText,
   int cchCharCount,
   uint dwTextFlags,
   ref RECT pBoundingRect,
   out RECT pExtentRect
);

Microsoft documentation: Link

Last updated