c# 使用什么 wpf 控件来显示文本文件

发布于 2024-11-09 08:43:54 字数 281 浏览 0 评论 0原文

在 wpf 应用程序中用于加载大文本文件的最佳控件是什么?它不仅仅是那么简单,我需要能够突出显示/更改某些线条的背景/颜色。我正在考虑使用 RichTextBox.. 但尽管我只是来询问其他人的想法。

我不需要编辑文本,只需突出显示有错误的行

编辑:啊我忘了提及,文本文件内容由程序处理,这会改变某些行的背景颜色。当程序无法找到某些错误行时,为用户提供更改以执行此操作会很高兴。

EDIT2:该应用程序用于解析日志文件,因此文件可能很大,超过 50 000 行。

Whats the best control to use in wpf applicaion for loading big text files into? And its not just simple as that, i need to be able to hightlight/change background/color of some lines. I was thinking of using RichTextBox.. but though i just come and ask what other people think.

I dont need to edit the text, just highlight lines with errors

EDIT: Ah i forgot to mention, text file content is processed by the program what will change the background color of some lines. Would be nice to give user a change to do that allso when the program failes to find some error lines.

EDIT2: The application is for parsing log files, so the files might be big, over 50 000 lines..

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

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

发布评论

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

评论(2

女中豪杰 2024-11-16 08:43:54

我不明白您是否只想显示文件或允许用户编辑它们。

无论哪种方式,也许 ScintillaNET 对您有用。

众所周知的文本编辑器,Notepad++ 使用 Scintilla :)

您可以在 http://sourceforge.net 获取 notepad++ 源代码/projects/notepad-plus/,但它是用 C++ 编写的,因此 API 与 .NET 中的 API 略有不同。

编辑

Notepad++ 能够显示大约 100-200MB 的文件。如果您需要比这更好的功能,则需要实现某种分页技术/虚拟模式(不要加载整个文件,仅加载根据当前滚动条位置将在屏幕上显示的部分)

如果 Scintilla 看起来有点矫枉过正,那么也许您只构建一个 DataGrid 会更好。如果日志条目由多个字段组成,这些字段可能会成为列,并且更容易阅读。如果您想走这条路,请首先将日志文件解析为 LogEntry 列表,然后使用数据绑定来绑定到它。您可以随着新行的添加而增量读取文件,以获得更好的用户体验。

I didn't understand if you only want to display files or allow user to edit them.

Either way, maybe ScintillaNET would be useful to you.

Well known text editor, Notepad++ uses Scintilla :)

You could grab notepad++ sources at http://sourceforge.net/projects/notepad-plus/, but It's written in c++, so the API would be a bit different than in .NET.

EDIT

Notepad++ is capable of displaying files of around 100-200MB. If you need better than that, you would need to implement some kind of paging technology/virtual mode (do not load entire file, only the portion that would be displayed on the screen depending on current scrollbar position)

If Scintilla seems an overkill, then maybe you'd be better off with simply building a DataGrid. If log entries consist of several fields, these could become columns and would be even easier to read. If you want to go that route, first parse your log file into a List of LogEntry, then use databinding to bind to it. You could read your file incrementally as new lines get added for better user experience.

西瑶 2024-11-16 08:43:54

我认为 RichTextBox 在这种情况下是最合适的,但正如 CharithJ 所说,您无法一次将整个日志加载到其中,这会对性能造成太大影响。

在这样的场景中我会做的是..我将有一个 Richtextbox 以及两个用于滚动的小向上和向下按钮。我只会一次加载一些日志文本,比如说 x 个字符。一旦用户单击向上或向下滚动按钮,我将从开始和结束位置删除一些文本,具体取决于用户单击的按钮(向上或向下),并基于此我将从 Richbox 中删除一些文本并附加一些其他文本。

您可以执行我上面建议的操作,或者另一种方法是扩展 RichTextBox 控件并实现仅将有限文本转发到 RichTextBox 以在时间。您可以处理滚动相关事件以更改 RichTextBox 的内容。

I think RichTextBox will be most appropriate in this case but as CharithJ said you cannot load whole log in to it at one time it will be too much performance hit.

What I would do in scenario like this is .. I will have a Richtextbox along with two small up and down buttons for kind of scroll. I will only load some text of log at one time let's say x number of characters. Once user clicks the up or down scroll button, I would remove some text from start and end depending on which button user have clicked, up or down and based on that I would remove some text from richbox and append some other.

Either you can do something like I suggested above, or one other way could be to extend the RichTextBox control and implement logic that only forwards a limited text to RichTextBox for display at a time. You can handle scroll related events to make changes in RichTextBox's content.

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