给出了类似的例子Here。他们还解决了maxLength问题 msdn
重要提示:请参阅文章中如何使用MaxLength。
private static void DrawALineOfText(PaintEventArgs e)
{
// Declare strings to render on the form.
string[] stringsToPaint = { "Tail", "Spin", " Toys" };
// Declare fonts for rendering the strings.
Font[] fonts = { new Font("Arial", 14, FontStyle.Regular),
new Font("Arial", 14, FontStyle.Italic),
new Font("Arial", 14, FontStyle.Regular) };
Point startPoint = new Point(10, 10);
// Set TextFormatFlags to no padding so strings are drawn together.
TextFormatFlags flags = TextFormatFlags.NoPadding;
// Declare a proposed size with dimensions set to the maximum integer value.
Size proposedSize = new Size(int.MaxValue, int.MaxValue);
// Measure each string with its font and NoPadding value and
// draw it to the form.
for (int i = 0; i < stringsToPaint.Length; i++)
{
Size size = TextRenderer.MeasureText(e.Graphics, stringsToPaint[i],
fonts[i], proposedSize, flags);
Rectangle rect = new Rectangle(startPoint, size);
TextRenderer.DrawText(e.Graphics, stringsToPaint[i], fonts[i],
startPoint, Color.Black, flags);
startPoint.X += size.Width;
}
}
Source
我以前听说过这个问题,它是一个Windows错误。当你做这样的疯狂事情时确实存在这种类型。解决方法是非常明显的,如果字符串包含超过一千个字符,那么你只是不在乎字符串可能有多宽,它永远不会适合。 – 2014-10-08 09:04:21