public Region[] MeasureCharacterRanges (string text, Font font, RectangleF layoutRect, StringFormat stringFormat) { if ((text == null) || (text.Length == 0)) return new Region [0]; if (font == null) throw new ArgumentNullException ("font"); if (stringFormat == null) throw new ArgumentException ("stringFormat"); int regcount = stringFormat.GetMeasurableCharacterRangeCount (); if (regcount == 0) return new Region[0]; IntPtr[] native_regions = new IntPtr [regcount]; Region[] regions = new Region [regcount]; for (int i = 0; i < regcount; i++) { regions[i] = new Region (); native_regions[i] = regions[i].NativeObject; } Status status = GDIPlus.GdipMeasureCharacterRanges (nativeObject, text, text.Length, font.NativeObject, ref layoutRect, stringFormat.NativeObject, regcount, out native_regions[0]); GDIPlus.CheckStatus (status); return regions; }