如何在C#.NET GUI应用程序中实现语法突出显示和自动完成功能? [英] How to implement Syntax Highlighting and Auto-Complete feature in C#.NET GUI Application?

查看:73
本文介绍了如何在C#.NET GUI应用程序中实现语法突出显示和自动完成功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做一个像应用程序这样的编辑器,它将突出显示代码(语法突出显示)并具有函数变量等的自动完成功能.能否请您提供一些教程链接或有关此的提示?我可以在富文本框"中实现这些功能吗?

注意:我已经阅读了这篇文章: ^ ].我不想使用任何外部库或工具来做到这一点.

解决方案

是的,可以使用RichTextBox完成.这并不容易,但是绝对有可能.无论如何,这个问题太复杂了,无法详细回答,所以我只能给您非常笼统的信息.

您将必须跟踪文本框中的更改,并在每次按键后分析文本以突出显示文本.使其正常工作可能很棘手,您肯定会遇到性能问题.您很可能需要使用多个线程来提高性能并保持应用程序的响应速度.

至于自动完成,它不能直接在RichTextBox中完成,但是您可以跟踪对文本所做的所有更改,并在必要时在某种子窗口中显示自动完成列表.

我曾经编写过这样的应用程序,我记得我找不到任何非常好的教程……但是,我在这里和那里发现了一些有用的技巧,我敢肯定,如果您稍作尝试,也会发现它们. /blockquote>

查看该文章的源代码.那应该使您对如何完成操作有所了解.它还将向您显示这不是一项微不足道的任务.

至于使用RichTextBox,则不是一个不错的起点.

Nick


您好,Chanchal,我实现了一个简单的语法突出显示并自动完成RichTextBox,并在代码编辑器中使用了它.
此处查看它

Note: I already read this article: Using ICSharpCode.TextEditor[^]. I don''t want to use any external library or tools to do that.

解决方案

Yes, it can be done using a RichTextBox. It is not easy, but it is definitely possible. Anyway, this question is way too complex to be answered in detail so I can only give you very general information.

You will have to track changes in the text box and parse the text after each key stroke to highlight the text. It might be tricky to make it work right and you will definitely run into performance problems. You will most probably need to use multiple threads to boost the performance a bit and to keep your application responsive.

As for auto-completing, it cannot be done directly in RichTextBox, but you can track all changes made to the text and, when necessary, display an auto-complete list in some kind of a child window.

I have written such application once and I remember I was not able to find any really good tutorial... However, I found several useful tips here and there, I''m sure you will find them too if you try a bit.


Look at the source code from that article. That should give you an idea of how it can be done. It will also show you that it is not a trivial task.

As for using a RichTextBox - no that is not a good place to start.

Nick


Hi Chanchal, I''ve implemented a simple syntax highlighting and auto-complete RichTextBox, and I used it in my code editor.
Check it out here. I hope it''s helpful. Regards!
Tony


这篇关于如何在C#.NET GUI应用程序中实现语法突出显示和自动完成功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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