SyntaxEditor - How to Change the Font?

1 Answer 101 Views
FontDropDownList SyntaxEditor
Troy
Top achievements
Rank 3
Bronze
Iron
Iron
Troy asked on 22 Mar 2023, 02:18 AM

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

 

1 Answer, 1 is accepted

Sort by
1
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 22 Mar 2023, 03:36 PM

Hi, Troy,

In order to change the font for RadSyntaxEditor, feel free to use the following approach: 

    Private Sub RadFontDropDownList1_SelectedFontChanged(sender As Object, e As EventArgs) Handles RadFontDropDownList1.SelectedFontChanged
        Dim ff As FontFamily = New FontFamily(Me.RadFontDropDownList1.SelectedFont)
        If ff.IsStyleAvailable(FontStyle.Regular) Then
            Dim font As Font = New Font(ff.Name, 10, FontStyle.Regular) 
            Me.RadSyntaxEditor1.SyntaxEditorElement.EditorFontSize = font.Size
            Me.RadSyntaxEditor1.SyntaxEditorElement.EditorFontFamily = New Telerik.WinControls.SyntaxEditor.UI.FontFamily(font.FontFamily.Name)
        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) 
                    Me.RadSyntaxEditor1.SyntaxEditorElement.EditorFontSize = font.Size
                    Me.RadSyntaxEditor1.SyntaxEditorElement.EditorFontFamily = New Telerik.WinControls.SyntaxEditor.UI.FontFamily(font.FontFamily.Name)
                    Exit For
                End If
            Next
        End If
    End Sub

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
FontDropDownList SyntaxEditor
Asked by
Troy
Top achievements
Rank 3
Bronze
Iron
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or