TextRenderer不画一个长字符串 [英] TextRenderer doesn't draw a long string

查看:205
本文介绍了TextRenderer不画一个长字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看看这个例子:

public partial class Form1 : Form
{
    private static string myString = null;

    private const int MAX_TEXT = 5460;

    public Form1()
    {
        InitializeComponent();

        StringBuilder builder = new StringBuilder();

        for (int i = 0; i < MAX_TEXT; i++)
        {
            builder.Append('a');
        }

        myString = builder.ToString();

        this.Paint += Form1_Paint;
    }

    void Form1_Paint(object sender, PaintEventArgs e)
    {
        TextRenderer.DrawText(
            e.Graphics,
            myString,
            this.Font,
            new Point(10, 30),
            Color.Black);
    }
}

当我设置了 MAX_TEXT 到5461,该字符串不绘制。你知道,如果本机机制有限制绘制文本,如果/或者我可以设置选项来得到它的工作?

When I set the MAX_TEXT to 5461, the string is not drawn. Do you know if the native mechanism has a limit to draw text, if/or I can setup the options to get it working?

在此先感谢。

推荐答案

我觉得你打的TextRenderer类,我认为这是调用引擎盖下的DrawTextEx API函数的限制。如果你试图把你的 builder.ToString()结果到一个TextBox,也不会出现任何。

I think you hit the limitation of the TextRenderer class, which I think is calling the DrawTextEx API function under the hood. If you try to put your builder.ToString() results into a TextBox, it won't show up either.

如果由于某种原因,你需要打印一个字符串,长的,你就必须恢复到拉绳方式:

If for some reason you need to print a string that long, you would have to revert back to the DrawString method:

e.Graphics.DrawString(myString, this.Font, Brushes.Black, new Point(10, 30));

这篇关于TextRenderer不画一个长字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆