Skip to content

Syntaxhighlighting

Julius Kirsch edited this page Jan 20, 2023 · 1 revision

Syntaxhighlighting

Use a predefined language:

There are many predefined syntaxhighlighting languages:

Batch ConfigFile C++ C# GCode Hex Html Javascript Json PHP QSharp Xml

textbox.CodeLanguage = TextControlBox.GetCodeLanguageFromId("C#");

When you don't want to use syntaxhighlighting you can either disable it completely or set the CodeLanguage to null:

Disable it:

textbox.SyntaxHighlighting = false;

Clear it:

textbox.CodeLanguage = null;

Create a custom langugage:

1. Create a new file with the extension .json

2. Paste the code below:

{
  "Highlights": [
    //highlights with code style formatting
    { 
      "CodeStyle": {
        "Bold": true, 
        "Underlined": true, 
        "Italic": true
      },
      "Pattern": "REGEX PATTERN",
      "ColorDark": "#ffffff", //color in dark theme
      "ColorLight": "#000000" //color in light theme
    },

    //highlights without code style formatting
    { 
      "Pattern": "REGEX PATTERN",
      "ColorDark": "#ffffff", //color in dark theme
      "ColorLight": "#000000" //color in light theme
    },
  ],
  "Name": "NAME",
  "Filter": "EXTENSION1|EXTENSION2", //.cpp|.c
  "Description": "DESCRIPTION",
  "Author": "AUTHOR"
}

Main file

Code Meaning
Name The id of the language
Filter The file extensions associated with the language
Description A description of the language
Author The author of the language
Highlights A list containing all the highlights

Highlight

Code Meaning
Pattern The Regex pattern matching the text to highlight
ColorDark The color of the matching pattern in dark mode
ColorLight The color of the matching pattern in light mode
CodeStyle The formatting of the matching pattern (Bold/Italic/Underlined)

CodeStyle

Code Meaning
Bold The matching pattern in bold
Italic The matching pattern in italic
Underlined The matching pattern in underlined

3. Load the language:

//Use a custom language:
var result = TextControlBox.GetCodeLanguageFromJson("JSON DATA"); //read the data from your file and pass it to the function
if(result.Succeed)
     textbox.CodeLanguage = result.CodeLanguage;