有没有办法加快在winforms文本框中显示大量文本? [英] Is there way to speed up displaying a lot of text in a winforms textbox?

查看:13
本文介绍了有没有办法加快在winforms文本框中显示大量文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法加快在 winforms 文本框中显示大量文本的速度?我的应用程序读取一个文件(最大可达 20MB),然后将其显示到一个文本框 (TextBoxX.Text = fileText;).

Is there way to speed up displaying a lot of text in a winforms textbox? My application reads a file (which can be as large as 20MB) and then displays it to a textbox (TextBoxX.Text = fileText;).

显示文本的过程非常缓慢,有时需要几分钟.问题在于,这个应用程序旨在向用户快速显示文件中的大量文本.

The process of displaying the text is extremely slow, it sometimes takes up to a few minutes. The problem is that this application is designed to show a lot of text in a file, quickly to the user.

有什么方法可以更快地做到这一点?也许使用某种缓存?

Is there any way to do this faster? Maybe use some kind of caching?

推荐答案

对代码进行最小更改的解决方案是将整个文件内容读入变量,然后在循环调用 Application 中将内容的块"附加到文本框.DoEvents() 在每次迭代中.

Solution with minimal change in code will be to read the whole file contents into variable, then append "chunks" of the contents to the textbox in a loop calling Application.DoEvents() in each iteration.

您可以在加载时显示Loading please wait..."消息,DoEvents 调用将确保您的应用程序不会同时被冻结".

You can show "Loading please wait..." message while it's still loading, the DoEvents call will ensure your application won't be "frozen" in the meanwhile.

这篇关于有没有办法加快在winforms文本框中显示大量文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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