控件查看包含大量文本的文件

发布于 2024-07-28 18:55:18 字数 166 浏览 11 评论 0 原文

有没有类似TextBox的WinForms控件,可以以只读模式显示大量文本(数百兆字节)? 当然,它应该无需立即将整个文件加载到内存中即可工作。

我正在尝试自己实现这一点,使用标准文本框,处理滚动和键盘事件并读取填充可见“窗口”所需的文本量。 但它仍然有很多问题,我觉得我正在重新发明轮子。

Is there a TextBox-like WinForms control that can show a large amount of text (hundreds of megabytes) in read-only mode? Of course it should work without loading the whole file into memory at once.

I'm trying to implement this myself, using a standard TextBox, processing scroll and keyboard events and reading the amount of text necessary to fill the visible "window". But it's still quite buggy, and I'm feeling that I'm reinventing the wheel.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

疯到世界奔溃 2024-08-04 18:55:40

分部分显示文本......每个文本框中有 10.000 个字符......我最近发现,如果你使文本框更大,程序在编辑文本或滚动时会运行得更快......

Display the text in parts.....10.000 characters in each text box....i recently discovered thet if you make the textbox bigger the program will run faster when editing the text or scrolling...

乱了心跳 2024-08-04 18:55:36

据我所知,不存在这样的控制。 很久以前我写过类似的控件,但它是针对 Delphi 的,但原理是相同的(读取有限的数据块并渲染它)。 因此,如果您决定自己实现它,然后远离 TextBox 控件,它不太适合这种需求。 我相信您应该使用所有自定义绘画创建新的 Control 后代。 这不是很容易,但却是唯一正确的方法。

There is no such control from what I know. Long time ago I have written similar control but it is for Delphi, but the principles are the same (read limited block of data and render it). So if you decided to implement it by yourself, then move away from TextBox control, it is not well suitable for such needs. I believe you should create new Control descendant with all custom painting. It is not very easy, but it is the only correct way.

近箐 2024-08-04 18:55:35

我不知道这样的控件(当您将单个维基百科页面放入其中时,RichTextBox 很慢,所以我很确定他将所有内容加载到内存中)。

我对 winforms 的经验是,您经常需要自定义默认控件以获得您想要的行为,即使它看起来微不足道(任何人都可以为 null DateTime 吗?)。 另一方面,它们确实提供了一个良好的基础,可以快速添加一两个简单的行为,而无需您自己完成所有操作。

我已经使用 winforms 控件几个月了,并且经常最终在我自己的控件中实现特定的(一些微不足道的,另一些复杂的)行为。

I've no knowledge of such a control (RichTextBox is slow when you put a single wikipedia page into it, so I'm quite sure he loads everything into memory).

My experience with the winforms is that you often need to customize defaults controls to obtain the behavior you want, even when it seems trivial (nullable DateTime anyone ?). On the other hand, they do offer a good base to add one or two simple behaviors quickly without having to do all by yourself.

I've been using winforms controls for several months and often ended up implementing specific (some trivial, others complex) behaviors in my own controls.

美羊羊 2024-08-04 18:55:32

我认为使用 Scintilla 或其包装 Scintilla.Net。 我认为它并没有那么完美,但它比 TextBoxRichtTextBox 好得多。

I think you got best chances by using Scintilla or its wrapper Scintilla.Net. I think it doesn't it job that perfect, but it makes it much better than TextBox or RichtTextBox.

呢古 2024-08-04 18:55:30

将“数百兆字节”的文本加载到控件中听起来是一个非常非常糟糕的主意,从内存/性能角度来看; 它可能会让你的程序崩溃。 不管怎样,你要如何阅读这几百万行呢? 您真的需要一直将整个文本放在那里吗? 也许,如果您有一个缓冲区并将少量文本加载到 RichTextBox 中,并且当您到达末尾(甚至接近末尾)时,只需加载接下来的 100 个(或任何其他文本),那就更好了量)行数。 或者,如果您正在搜索某些内容,请搜索关键字并将相关文本放入 RichTextBox 中。 这实际上取决于您打算做什么。

Loading "hundreds of megabytes" of text into a control sounds like a very, very bad idea memory/performance wise; it will likely crash your program. Anyway, how are you going to read all those millions of lines? Do you really need the whole text in there all the time? Mabye it would be better if you had a buffer and loaded small amounts of text into a RichTextBox and when you reach the end (or even near the end), simply load up the next 100 (or any other amount) of lines. Or, if you are searching for something, search for your keywords and put the relevant text in the RichTextBox. It really depends on what you are planning to do.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文