How to Syntax Highlight in a RichTextBox [C#]?

后端 未结 6 2049
别那么骄傲
别那么骄傲 2020-12-13 20:32

How do I syntax highlight in a richtextbox control AS THE USER TYPES and USING A String[] keywords. I will be publishing a lightweight notepad to the web soon

6条回答
  •  一向
    一向 (楼主)
    2020-12-13 20:56

    Not exactly an answer to your question, but have you looked at the text editor component from SharpDevelop? It's quite lightweight (<200kB IIRC), can be easily embedded in WinForms applications and has syntax highlighting for several languages built in.

    Otherwise, you might want to look at this CodeProject page. It reformats the RTF while you type, which is not very efficient for large files, and it contains a few creepy catch (Exception) { } blocks, so I'm not sure if I would use it in a life-critical application, but it's definitely a good starting point to see how it can be done.

提交回复
热议问题