System.Windows.Forms.TabControl.MeasureStringWidth C# (CSharp) Method

MeasureStringWidth() private method

private MeasureStringWidth ( Graphics graphics, string text, Font font ) : int
graphics Graphics
text string
font Font
return int
		private int MeasureStringWidth (Graphics graphics, string text, Font font) 
		{
			if (text == String.Empty)
				return 0;
			StringFormat format = new StringFormat();
			RectangleF rect = new RectangleF(0, 0, 1000, 1000);
			CharacterRange[] ranges = { new CharacterRange(0, text.Length) };
			Region[] regions = new Region[1];

			format.SetMeasurableCharacterRanges(ranges);
			format.FormatFlags = StringFormatFlags.NoClip;
			format.FormatFlags |= StringFormatFlags.NoWrap;
			regions = graphics.MeasureCharacterRanges(text + "I", font, rect, format);
			rect = regions[0].GetBounds(graphics);

			return (int)(rect.Width);
		}