Table of Contents

Code Editor Overview

AlterNET Code Editor is a .NET component library that brings efficient code editing functionality into your WinForms and WPF .NET applications. It provides code editing capabilities such as syntax highlighting, code completion and outlining, visual indicators for bookmarks, line styles, syntax errors, and more.

The main components in the package are SyntaxEdit for WinForms and TextEditor for WPF. These controls provide text editing functionality and support almost all the features that can be found in the Visual Studio.NET code Editor, including customizable syntax highlighting, code outlining, code completion, unlimited undo/redo, bookmarks, word wrap, drag-n-drop, built-in search/replace dialogs, multiple views of the same text, displaying gutter, margin, line numbers and many more.

Code Editor includes a set of quick-start projects, each designed to highlight the component's specific features.

Code Editor

Below is a brief overview of these projects:

Scroll Bar Annotations - Shows how text edit control can display markers about current line, syntax errors, bookmarks, modified lines and search results on the vertical scrollbar area.

Syntax Highlighting - Shows how text edit control can highlight syntax when working with different programming languages.

Code Completion - Shows how to display code completion while you type, either by getting code completion information from the parser or programmatically.

Code Outlining - Shows how to use outlining; either provided by parser, or programmatically.

Selection - Shows how to use different options to control text selection appearance and behavior in the text editor.

Undo/Redo - Shows how to use various options to control undo/redo behavior.

Search and Replace - Shows how to use built-in Search and Replace dialogs and implement search across multiple documents.

Gutter - Shows how to control the appearance of the gutter area and display various indicators on it.

Bookmarks - Shows how to set and navigate through numbered and though-loop bookmarks and how to set bookmarks navigation across multiple documents.

Word Warp - Shows how to configure text edit control to wrap words at the right edge of the visible area or a given position.

Line Styles - Shows how to display line indicators on the text editor control area and associated images on the gutter.

Print and Preview - Shows how to print and preview text editor control content and set different printing options.

Code Snippets - Shows how to display and use predefined code templates to speed up entering frequently used fragments of code.

Multiple Views and Split View - Shows how to configure text editor windows to display and edit the same text content.

Margin - Shows how to use various options controlling the appearance and behavior of the Margin line and UserMargin area next to the gutter.

HyperText - Shows how to highlight hyperlinks in the text.

Page Layout - Shows how to configure text edit control to display its content as if it is positioned on the printed page.

Miscellaneous - Shows how to display white-space symbols and background images, as well as highlight matching brackets.

Customize - Shows an example of an options dialog that allows changing display settings of the text edit control.

Roslyn-Based Parsing - Shows how to link text edit control to Microsoft Roslyn-based parsers that perform full syntax and semantic analysis of the C# or Visual Basic code and provide features like code completion, code outlining and syntax/semantic error highlighting.

TypeScript Parsing - Shows how to link text edit control to Microsoft TypeScript-based parsers that perform full syntax and semantic analysis of the TypeScript or JavaScript code and provide features like code completion, code outlining, and syntax/semantic error highlighting.

Advanced Syntax Parsing - Shows how to link text edit control to parsers that perform syntax analysis for a set of programming languages and provide features like code completion, code outlining, and syntax error highlighting.

Snippet Parsers - Shows how to implement C# or Visual Basic syntax and semantic analysis for sub-set of the code, like class or method body.

SQL DOM Parser - Shows how to implement syntax analysis for Microsoft SQL.

XAML Parser - Shows how to implement syntax analysis for XAML.

Lsp-based parsers (C/C++, Java, Python, Lua, XML, and PowerShell) - Shows how to implement syntax analysis for these languages using native servers.

Lsp Multiple Files - Shows how to combine multiple LSP documents into a single workspace.

Python Parsing - Shows how to implement syntax analysis for Python and IronPython.

Creating your first project

The first thing to do after creating a new WinForms or WPF application is to place the SyntaxEdit or TextEditor controls. These controls are the central components in the package, and in many cases, they are the only ones that need to be placed on the form. These controls look similar to the standard multi-line text box, except for having a gray band on the left of its client area, used to display line numbers, bookmarks, and other visual indicators.

The following example demonstrates how to load text into the editor and save it. Use the LoadFile method to load text from the file. The first parameter specifies the name of the file to be loaded into the control. The optional second parameter specifies encoding.

    edit.LoadFile(openFileDialog1.FileName);

Saving of the text is performed similarly:

    edit.SaveFile(saveFileDialog1.FileName);

It is possible to load text from streams instead of files, by substituting the previous two functions by LoadStream and SaveStream.

Working with text

The Code Editor package includes non-visual components: TextSource (or TextSource for WPF applications). For WindowsForms applications TextSource is accessible through the Microsoft Visual Studio toolbox. The SyntaxEdit and TextEditor controls do not store the text being edited. This task is offloaded to the TextSource components, which provide methods to manipulate the text content. Text edit controls can have TextSource explicitly assigned and use an internally created one in case it's not set. It gives a clear separation between visualization and data layers. Also, it makes it possible to implement features like multiple views of the same text by assigning a single TextSource to several text editors. Visually, these editors can be placed in a single window separated by a splitter control or multiple windows. Most TextSource components' methods are also available via the edit controls.