Telerik Forums
UI for WinForms Forum
1 answer
24 views

Hi,

I have develop a custom tagger in order to format some specific words.

My problem is that the format is applying to this words even if they are used as strings (inside quotes).

I would like that the format only applies when the word is not in quotes.

In. Ex:

WORD -> Apply Format

"WORD" -> Do not apply format

 

This is my code:

using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using AutoMapper.Internal;
using Telerik.WinControls.UI;
using Telerik.WinForms.Controls.SyntaxEditor.Taggers;
using Telerik.WinForms.Controls.SyntaxEditor.UI;
using Telerik.WinForms.SyntaxEditor.Core.Tagging;

namespace Simulation.UX.Forms.Controls.Neptune
{
    public class CustomTagger : CSharpTagger
    {
        public static readonly ClassificationType CustomClassificationType = new("Custom");
        public static readonly Dictionary<string, ClassificationType> WordsToClassificationType = new();
        public static readonly TextFormatDefinition Format = new(new SolidBrush(Color.DarkGoldenrod));

        private readonly List<string> _words;

        public NeptuneTagger(RadSyntaxEditorElement editor, List<string> words) : base(editor)
        {
            _words = words;
        }

        protected override Dictionary<string, ClassificationType> GetWordsToClassificationTypes()
        {
            Dictionary<string, ClassificationType> baseTypes = base.GetWordsToClassificationTypes();

            _words?.ForAll(w =>
            {
                if (!baseTypes.ContainsKey(w))
                {
                    baseTypes.Add(w, CustomClassificationType);
                }
            });

            return baseTypes;
        }
    }
}
 
Dinko | Tech Support Engineer
Telerik team
 answered on 30 Apr 2025
1 answer
118 views
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Telerik.Windows.Controls;

using Telerik.WinForms.Controls.SyntaxEditor.Taggers;
using Telerik.WinForms.SyntaxEditor.Core.Tagging;
using Telerik.WinControls.UI;
using Telerik.WinForms.Controls.SyntaxEditor.UI;
using System.IO;

namespace WindowsFormsApp12
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public class PythonTagger : WordTaggerBase
        {
            private static readonly string[] Keywords = new string[]
    {
        "False", "None", "True", "and", "as", "assert","break", "class",
        "continue", "def", "del", "elif", "else", "except", "for", "from",
        "global", "if", "import", "in", "is", "lambda", "nonlocal", "not",
        "or", "pass", "raise", "finally", "return", "try", "while", "with", "yield"
    };

            private static readonly string[] Comments = new string[]
    {
        "#"
    };

            private static readonly string[] Operators = new string[]
    {
        "+", "-",  "*", "/"
    };

            public static readonly ClassificationType FruitsClassificationType = new ClassificationType("Fruits");

            private static readonly string[] Fruits = new string[]
    {
        "apple", "banana",  "cherry"
    };

            private static readonly Dictionary<string, ClassificationType> WordsToClassificationType = new Dictionary<string, ClassificationType>();

            static PythonTagger()
            {
                WordsToClassificationType = new Dictionary<string, ClassificationType>();

                foreach (var keyword in Keywords)
                {
                    WordsToClassificationType.Add(keyword, ClassificationTypes.Keyword);
                }

                foreach (var preprocessor in Operators)
                {
                    WordsToClassificationType.Add(preprocessor, ClassificationTypes.Operator);
                }

                foreach (var comment in Comments)
                {
                    WordsToClassificationType.Add(comment, ClassificationTypes.Comment);
                }

                foreach (var comment in Fruits)
                {
                    WordsToClassificationType.Add(comment, FruitsClassificationType);
                }
            }

            public PythonTagger(RadSyntaxEditorElement editor)
                : base(editor)
            {
            }

            protected override Dictionary<string, ClassificationType> GetWordsToClassificationTypes()
            {
                return PythonTagger.WordsToClassificationType;
            }

            protected override bool TryGetClassificationType(string word, out ClassificationType classificationType)
            {
                int number;

                if (int.TryParse(word, out number))
                {
                    classificationType = ClassificationTypes.NumberLiteral;
                    return true;
                }

                return base.TryGetClassificationType(word, out classificationType);
            }
        }


        private void Form1_Load(object sender, EventArgs e)
        {
            PythonTagger pythonTagger = new PythonTagger(this.radSyntaxEditor1.SyntaxEditorElement);
            if (!this.radSyntaxEditor1.TaggersRegistry.IsTaggerRegistered(pythonTagger))
            {
                this.radSyntaxEditor1.TaggersRegistry.RegisterTagger(pythonTagger);
            }

            this.radSyntaxEditor1.TextFormatDefinitions.AddLast(ClassificationTypes.NumberLiteral, new TextFormatDefinition(new SolidBrush(Color.Red)));
            this.radSyntaxEditor1.TextFormatDefinitions.AddLast(ClassificationTypes.Operator, new TextFormatDefinition(new SolidBrush(Color.YellowGreen)));
            this.radSyntaxEditor1.TextFormatDefinitions.AddLast(PythonTagger.FruitsClassificationType, new TextFormatDefinition(new SolidBrush(Color.LightCoral)));


            StreamReader  reader = new StreamReader(@"C:\Python27amd64\Lib\msilib\text.py");
            {
                radSyntaxEditor1.Document = new     Telerik.WinForms.SyntaxEditor.Core.Text.TextDocument(reader);
            }


        }

        private void radMenuItem2_Click(object sender, EventArgs e)
        {
            StreamReader reader = new StreamReader(@"C:\Python27amd64\Lib\ctypes\util.py");
            {
                radSyntaxEditor1.Document = new Telerik.WinForms.SyntaxEditor.Core.Text.TextDocument(reader);
            }

        }

        private void radSyntaxEditor1_Click(object sender, EventArgs e)
        {

        }
    }
}
Nadya | Tech Support Engineer
Telerik team
 answered on 01 Nov 2023
1 answer
121 views

Hi,

I'm looking into the viability of using the WinForms RadSyntaxEditor for a small project.

I think I've come across a bug when it comes to DPI scaling.

The component itself seems to work fine with DPI scaling except for the search/find functionality. When you search for some text and click to go to the first instance it finds, the actual text is off screen, though it is highlighted correctly (when you scroll down you can see it highlighted).

If I set the CaretPosition manually to a line further in the document, it also displays correctly so it seems to be specifically limited to the  built-in Search/Find panel.

This is easy to replicate by changing Windows display scale to anything other than 100%.

Nadya | Tech Support Engineer
Telerik team
 answered on 26 Oct 2023
1 answer
91 views

I am attempting to add a RadSyntaxEditorElement to Telerik Chat UI for Winforms using 2023.3.1010 Trial.

I receive a null reference exception in RadSyntaxEditorElement.cs > SyncZoomComboText line 1312. It says base.Dispatcher = null. (see attached image).

 

Is it possible to add the SyntaxEditorElement to chat?  If, not do you have any other recommendations for display code in chat?

 

Here is my test code modified from the examples found on your site.

        public class MyCodeMessageItemElement : TextMessageItemElement
        {
            protected override Type ThemeEffectiveType
            {
                get
                {
                    return typeof(TextMessageItemElement);
                }
            }

            protected override LightVisualElement CreateMainMessageElement()
            {
                return new CustomCodeMessageBubbleElement();
            }

            public override void Synchronize()
            {
                base.Synchronize();
                CustomCodeMessageBubbleElement bubble = this.MainMessageElement as CustomCodeMessageBubbleElement;
                bubble.DrawText = false;
            }
        }



        public class CustomCodeMessageBubbleElement : ChatMessageBubbleElement
        {
            protected override Type ThemeEffectiveType
            {
                get
                {
                    return typeof(ChatMessageBubbleElement);
                }
            }

            //RadTextBoxControlElement textBoxElement;
            RadSyntaxEditor radSyntaxEditor;
            RadSyntaxEditorElement radSyntaxEditorElement;

            public RadSyntaxEditor SyntaxEditor1
            {
                get
                {
                    return this.radSyntaxEditor;
                }
            }

            protected override void CreateChildElements()
            {
                base.CreateChildElements();
                radSyntaxEditorElement = new RadSyntaxEditorElement();
                radSyntaxEditorElement.ZoomComboBox.Enabled = false;
                //radSyntaxEditor.ContextMenuOpening += textBoxElement_ContextMenuOpening;
                this.Children.Add(radSyntaxEditorElement);
            }

            //private void textBoxElement_ContextMenuOpening(object sender, TreeBoxContextMenuOpeningEventArgs e)
            //{
            //    foreach (RadItem item in e.ContextMenu.Items)
            //    {
            //        if (item.Text.Contains("&Copy"))
            //        {
            //            item.Visibility = ElementVisibility.Visible;
            //        }
            //        else
            //        {
            //            item.Visibility = ElementVisibility.Collapsed;
            //        }
            //    }
            //}

            public override string Text
            {
                get
                {
                    return base.Text;
                }
                set
                {
                    base.Text = value;
                    this.radSyntaxEditor.Text = value;
                }
            }
        }

Dess | Tech Support Engineer, Principal
Telerik team
 answered on 20 Oct 2023
1 answer
149 views

I'm using the  example for the radfontdropdownlist control to attempt to set the font for the radsyntaxeditor.  So far, I haven't had any luck changing it.    

Here is an example:

I attempted to set editor.SyntaxEditorElement.Font = font as well, but while that doesn't blow up, it doesn't seem to change anything either.

Here's the full code for this event:

    Private Sub fontDropdown_SelectedFontChanged(sender As Object, e As EventArgs) Handles fontDropdown.SelectedFontChanged
        Dim editor As RadSyntaxEditor = GetActiveEditor()
        If IsNothing(editor) Then Exit Sub
        Dim ff As FontFamily = New FontFamily(fontDropdown.SelectedFont)
        If ff.IsStyleAvailable(FontStyle.Regular) Then
            Dim font As Font = New Font(ff.Name, 10, FontStyle.Regular)
            editor.SyntaxEditorElement.EditorFontFamily = font.FontFamily
        Else
            For Each style As FontStyle In [Enum].GetValues(GetType(FontStyle))
                If ff.IsStyleAvailable(style) Then
                    Dim font As Font = New Font(ff.Name, 10, style)
                    editor.Font = font
                    Exit For
                End If
            Next
        End If

    End Sub

 

Dess | Tech Support Engineer, Principal
Telerik team
 answered on 22 Mar 2023
1 answer
175 views

I'm trying to save the current zoom level that a user has set for a document.   I can get the value of the zoom level, but what I can't figure out how to do, is set the zoomcombobox to that value.

As an example, the default combo box has a list of values.  If a user sets it to say 150%, I can save that value.  I can use the zoomto method to set it and the document will scale to 150%.  However, this doesn't change the zoomcombobox value, it stays at whatever it was (default of 100%).

The next problem is, the user can CTRL-Mousewheel to change the zoom level.  This will add values to the zoomcombobox that were not previously there (meaning, the values will be different than those available in the zoomcombobox).  Not really a problem on the surface, the document scales correctly, the zoomcombobox has the correct values.

But, if I reload the document and want to reset the zoom level to the users zoom preference, the odds are, the scale is not in the default set of values for the zoomcombobox.  

I hope this makes some sense. =)

Dinko | Tech Support Engineer
Telerik team
 answered on 22 Mar 2023
1 answer
96 views

Reading this document: https://docs.telerik.com/devtools/winforms/controls/syntax-editor/features/word-wrap

States that wordwrap should now be a thing.  However, it isn't for me.

 

I've updated to the latest Telerik (already was), and no luck.

Dess | Tech Support Engineer, Principal
Telerik team
 answered on 14 Mar 2023
1 answer
137 views

Basically what the title says.  I've selected part of a document, and I want to replace only part of the text, within that selection.  Is this possible?  I've been trying various things, but so far, no luck.

In short, I've added commenting to my text.  That works fine, but I can't uncomment (remove the comment characters) from the selected text.

Troy
Top achievements
Rank 3
Bronze
Iron
Iron
 answered on 12 Mar 2023
1 answer
109 views

Hi,

with custom taggers is it possibile to manage insentive custom grammar?

thank you

Dess | Tech Support Engineer, Principal
Telerik team
 answered on 14 Feb 2023
1 answer
213 views

First, thanks for the awesome stuff, getting it going was easy.

However, I'm having a few issues and can't seem to figure out a way around them.  I'm trying to make a JSON tagger.

Here is how I'm defining things:


    Private Shared ReadOnly Keywords As String() = New String() {""""}
    Private Shared ReadOnly Operators As String() = New String() {"{", "}", "[", "]", ":", ","}


Here is an example of the output

The problems I see are:

The second double quote isn't colored like the first one.

The colon isn't colored

The comma after the double quote isn't colored

The closing brace and comma aren't colored

Also, is there a way to highlight the text between characters?  I'd like to highlight the keys and values, and differently from each other if possible.

I'm sure I'm doing it wrong, but haven't been able to figure it out.

Thanks!

Dess | Tech Support Engineer, Principal
Telerik team
 answered on 13 Feb 2023
Narrow your results
Selected tags
Tags
GridView
General Discussions
Scheduler and Reminder
Treeview
Dock
RibbonBar
Themes and Visual Style Builder
ChartView
Calendar, DateTimePicker, TimePicker and Clock
DropDownList
Buttons, RadioButton, CheckBox, etc
ListView
ComboBox and ListBox (obsolete as of Q2 2010)
Chart (obsolete as of Q1 2013)
Form
PageView
MultiColumn ComboBox
TextBox
RichTextEditor
PropertyGrid
Menu
RichTextBox (obsolete as of Q3 2014 SP1)
Panelbar (obsolete as of Q2 2010)
PivotGrid and PivotFieldList
Tabstrip (obsolete as of Q2 2010)
MaskedEditBox
CommandBar
PdfViewer and PdfViewerNavigator
ListControl
Carousel
Diagram, DiagramRibbonBar, DiagramToolBox
GanttView
Panorama
New Product Suggestions
Toolstrip (obsolete as of Q3 2010)
VirtualGrid
AutoCompleteBox
Label
Spreadsheet
ContextMenu
Panel
Visual Studio Extensions
TitleBar
Documentation
SplitContainer
Map
DesktopAlert
CheckedDropDownList
ProgressBar
TrackBar
MessageBox
Rotator
SpinEditor
StatusStrip
CheckedListBox
LayoutControl
Wizard
ShapedForm
TextBoxControl
Conversational UI, Chat
DateTimePicker
CollapsiblePanel
TabbedForm
CAB Enabling Kit
GroupBox
DataEntry
ScrollablePanel
ScrollBar
WaitingBar
ImageEditor
Tools - VSB, Control Spy, Shape Editor
BrowseEditor
DataFilter
ColorDialog
FileDialogs
Gauges (RadialGauge, LinearGauge, BulletGraph)
ApplicationMenu
RangeSelector
CardView
WebCam
Barcode
BindingNavigator
PopupEditor
RibbonForm
Styling
TaskBoard
Callout
ColorBox
PictureBox
FilterView
NavigationView
Accessibility
VirtualKeyboard
DataLayout
ToastNotificationManager
ValidationProvider
CalculatorDropDown
Licensing
Localization
TimePicker
ButtonTextBox
FontDropDownList
BarcodeView
BreadCrumb
Security
LocalizationProvider
Dictionary
Overlay
Flyout
Separator
SparkLine
TreeMap
StepProgressBar
SplashScreen
ToolbarForm
NotifyIcon
DateOnlyPicker
Rating
TimeSpanPicker
Calculator
OfficeNavigationBar
TaskbarButton
HeatMap
SlideView
PipsPager
AIPrompt
TaskDialog
TimeOnlyPicker
+? more
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?