- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
static public int MeasureDisplayStringWidth(Graphics graphics, string text,
Font font)
{
const int width = 32;
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap (width, 1,
graphics);
System.Drawing.SizeF size = graphics.MeasureString (text, font);
System.Drawing.Graphics anagra = System.Drawing.Graphics.FromImage(bitmap);
int measured_width = (int) size.Width;
if (anagra != null)
{
anagra.Clear (Color.White);
anagra.DrawString (text+"|", font, Brushes.Black,
width - measured_width, -font.Height / 2);
for (int i = width-1; i >= 0; i--)
{
measured_width--;
if (bitmap.GetPixel (i, 0).R != 255) // found a non-white pixel ?
break;
}
}
return measured_width;
}
Ищем размер нарисованной строки. Не моё. Нашел на codeproject.
(Вместо MeasureCharacterRanges)