Syntax-highlighting textbox for Winforms, ASP.NET, WPF

后端 未结 3 1565
悲&欢浪女
悲&欢浪女 2021-02-19 20:22

I\'m looking for a syntax-highlighting Textbox component, preferably free, with source, and capable of being used in Winforms, ASP.NET and WPF alike. Also, it should support not

相关标签:
3条回答
  • 2021-02-19 20:28

    I'm with you marc: I'd love to see an extensible syntax highlighting framework that could generate a tokenized "document" object which could then be displayed via controls for each display framework. This way the parser/tokenizer could be written once!

    The best I can say is that this thread suggests that ActiProSoftware is working on a WPF control for their syntax highlighter.

    0 讨论(0)
  • 2021-02-19 20:33

    All those platforms are completely different and each have their own rendering display methods. So there won't be any universal control that does all. Each platform will have a separate control

    However, one can implement a web control and use it in a page. Then a browser object in winforms or wpf can use the page address to display it

    0 讨论(0)
  • 2021-02-19 20:49

    Perhaps consider CodeMirror items for the web. Obviously this won't work for WPF as you'd asked, but it'll work for any web framework - Webforms, ASP.NET MVC, plain HTML, PHP and others.

    CodeMirror is a JavaScript library that can be used to create a relatively pleasant editor interface for code-like content ― computer programs, HTML markup, and similar. If a parser has been written for the language you are editing (see below for a list of supported languages), the code will be coloured, and the editor will help you with indentation.

    Parsers for :

    • JavaScript
    • XML/HTML
    • CSS
    • HTML mixed-mode
    • SPARQL
    • HTML+PHP mixed-mode
    • Python
    • Lua
    • Ruby
    • SQL
    • PLSQL
    • diff
    • Groovy
    • C#
    • Scheme
    • Java
    • XQuery
    • OmetaJS
    • Freemarker

    Implementation:

    <textarea  rows="30" cols="120" id="someCode" >
        //some comments
        var foo = "bar";
    </textarea>
    

    You include 2 .js references, and then this bit of JavaScript replaces your textarea elements with new syntax highlighted elements.

    <script type="text/javascript">
        var textarea = document.getElementById('someCode');
        var editor = new MirrorFrame(CodeMirror.replace(textarea), {
            height: "350px",
            content: textarea.value,
            parserfile: ["tokenizejavascript.js", "parsejavascript.js"],
            stylesheet: "css/jscolors.css",
            path: "js/",
            autoMatchParens: true
        });
    </script>
    

    The CodeMirror manual helps.

    Also consider the WikiPedia entry for Comparison of JavaScript-based source code editors

    0 讨论(0)
提交回复
热议问题