38

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.

Kredns
  • 36,461
  • 52
  • 152
  • 203

8 Answers8

37

Scintilla.NET is probably what you're looking for

Fernando
  • 4,029
  • 1
  • 26
  • 35
  • 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 – Vin Jul 06 '09 at 15:58
  • Thanks, this seems to be exactly what I'm looking for. – neo2862 Oct 14 '09 at 12:16
  • 3
    Note that the above answer is nearly two years older than some of the submissions, below. For example, the [answer from David Maron](http://stackoverflow.com/a/6136658/1028230) is excellent, and includes a [link to a blog](http://www.csharpblog.co.cc/2010/09/syntax-highlighting-control.html) with a well-done explanation of how to use its lib, an argument against Scintilla.NET, and sample code. – ruffin Apr 27 '12 at 14:22
  • 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 – Hopeless Aug 09 '18 at 11:30
  • 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 Jan 16 '19 at 07:55
18

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.

volody
  • 6,946
  • 3
  • 42
  • 54
13

As Open Source alternatives, give a look to:

Christian C. Salvadó
  • 807,428
  • 183
  • 922
  • 838
9

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

Kobus Smit
  • 1,775
  • 2
  • 18
  • 30
David Maron
  • 169
  • 2
  • 2
7

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.

Mike Hofer
  • 16,477
  • 11
  • 74
  • 110
  • 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? – Mike Hofer May 04 '12 at 17:32
4

Not sure if there is any out of the box non-thirdparty solution to this.

But, have you looked at Actipro SyntaxEditor component. LinqPad, the ubercool linq tool uses it for syntax highlighting and intellisense.

Vin
  • 6,115
  • 4
  • 41
  • 55
4

Check out the AvalonEdit control. There is a good article on CodeProject explaining how to use it.

Dmitri Nesteruk
  • 23,067
  • 22
  • 97
  • 166
2

you can try this http://www.codeproject.com/KB/edit/SyntaxHighlighting.aspx

imaximchuk
  • 748
  • 5
  • 13