A textbox/richtextbox that has syntax highlighting? [C#]

50,363

Solution 1

Scintilla.NET is probably what you're looking for

Solution 2

Just recently have found a nice control from codeproject Fast Colored TextBox for syntax highlighting.

The only issue with using Rich Text Box as highlighter is slow performance on coloring, in cases when the size of the document is big. For a medium size documents this issue can be fixed by delayed highlighting.

Solution 3

As Open Source alternatives, give a look to:

Solution 4

Add ICSharpCode.TextEditor assembly reference to a project, choose assembly and controls for Visual Studio Toolbox. After that, you can put control to the Form. Surprisingly, you will not see Property to choose syntax highlight schema. Instead of this, you have to use method SetHighlighting. String parameter sets highlighting schema from available schemas list. These schemas are embedded into the control.

How to use, change schemas and download sample, look following article

Solution 5

If you're willing to pay for a control, I highly recommend this one: QWhale Syntax Edit. It's got a ton of features, comes with source code, and supports a lot of languages. I use it myself for C#, VB.NET, SQL (MS & Oracle), and it's got everything that VS provides.

Share:
50,363
vishwas kumar
Author by

vishwas kumar

Bad programming is easy. Idiots can learn it in 21 days, even if they are dummies. --Teach Yourself Programming In Ten Years

Updated on July 31, 2020

Comments

  • vishwas kumar
    vishwas kumar almost 4 years

    Where can I find a control for WinForms that will highlight source code pasted into it? I would like one that has syntax highlighting support for many different languages but if it only works with C# I would be fine with that also.

  • thebretness
    thebretness about 15 years
    This is good and thanks for the link, good to know there is atleast one open-source alternative, but it leaves a lot to desire to get the VS look and feel
  • neo2862
    neo2862 over 14 years
    Thanks, this seems to be exactly what I'm looking for.
  • ruffin
    ruffin about 12 years
    Note that the above answer is nearly two years older than some of the submissions, below. For example, the answer from David Maron is excellent, and includes a link to a blog with a well-done explanation of how to use its lib, an argument against Scintilla.NET, and sample code.
  • hachu
    hachu about 12 years
    Downvoted? For? He wants a tool that provides the Visual Studio look and feel. I recommended one that supports a vast array of languages, the VS look and feel, and isn't a horrible burden on the wallet. How did this answer fail to satisfy the question?
  • Hopeless
    Hopeless almost 6 years
    do you know what built-in languages supported in ScintillaNet exactly means? I don't find any way to understand its built-in features, we always have to set the KeyWords ourself and setup the styles, everything makes it look just like customize, not built-in and ready to use at all. I know that the keywords may be added later when the language is developing, but the base set should be added (as what built-in means) and additional set can be added/removed by the custom code. Too many code to setup the control for highlighting a very familiar language like SQL
  • Larry
    Larry over 5 years
    Scintilla.NET is basically a wrapper around an activeX control : any method call runs deferred, and I had so many trouble running advanced scenarios as synchronizing several instances including regions expand/collapse for example. I prefer using FCTB (nuget), it uses vanilla .NET and runs perfectly. This is a bit sad because Scintilla is well known and great, but Scintilla.NET seems only suitable for a simple scenario.
  • Larry
    Larry over 5 years
    FCTB has evolved a lot since and is the way to go IMHO.