Changing Background and Textcolor for a custom Dark Theme

SyntaxEditor for Windows Forms Forum

Posted 4 years ago by Jafran Majeau
Version: 20.1.0400
Avatar

Hello, I've made some research to make sure I wasn't asking something that was already posted, but the most relevant post I found were 12 years old, so I figured I might need something more recent.

I've been trying to use the ActiproSoftware.SyntaxEditor.SyntaxEditor control, and I have a multiple color themes setup.

When I try to change the this.myEditor.ForeColor or this.myEditor.BackColor (myEditor being an aforementioned SyntaxEditor), nothing seems to change. I'm essentially trying to have the editor fit the different themes (for example, Dark Theme by changing the background color to black and the text color to white). Is there a way to get this result?

I apologize if this is something that's already been explained.

Comments (10)

Answer - Posted 4 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

In the most recent 2020.1 version, we updated the SyntaxEditor codebase to use a similar setup to the newer WPF and UWP versions in terms of how text is highlighted.

You would want to read through the "SyntaxEditor / User Interface Features / Theme and Highlighting Style Features / Highlighting Style Registries" topic in the documentation that comes with the product.  That explains how it works.

Basically there is a highlighting style registry.  You register a highlighting style for each classification type (keyword, string, etc.) and the colors in the styles get used for syntax highlighting.  We also have numerous special "display" classification types for things like plain text (the default foreground/background, margins, whitespace, etc.) that you can register styles for.

Those should allow you to customize the entire appearance of the editor.  The one thing we know we still have to do is allow the scrollbars to render differently in custom themes.  That is a high priority TODO item for the next build.  We also want to wire it up so that ForeColor/BackColor can override the plain text display classification type style registration.


Actipro Software Support

Posted 4 years ago by Jafran Majeau
Avatar

Sorry for the very, very late reply. The recent conundrum had shifted my priorities and work to other concerns, but I'm finally looping back to where I was some months ago.

So if I understand correctly, I should be able to set up various themes for the SyntaxEditor control to have it fit with my other themes. That's good to know! I'd still have one more question if that's okay and I'd likely need help for something too (again, if possible).

1. Are there some default syntax highlight themes that can be used?

2. Although I do use your product, I've been unable to track down the documentation, is there anyway I could get a digital copy of it or have access to a sort of tutorial on how to use Syntax Highlighting?

Again, sorry for the delay.

[Modified 4 years ago]

Posted 4 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Jafran,

1) We do include a "/ProductSamples/SyntaxEditorSamples/Languages/Themes/Dark.vssettings" file in the Sample Browser project with some dark-themed highlighting styles for common languages.  That can be loaded from the AmbientHighlightingStyleRegistry.Instance.ImportHighlightingStyles method after your language's classification types have been registered with AmbientHighlightingStyleRegistry.Instance, which happens when the language first is used.

2) The documentation is a CHM file that gets installed and is available from the Actipro group in the Windows Programs menu.


Actipro Software Support

Posted 4 years ago by Jafran Majeau
Avatar

Thank you! I've found them. I appreciate the help.

Posted 4 years ago by Jafran Majeau
Avatar

Hello, sorry to open this up again. I'm still having some issues.

I've been able to find the Highlighting Style section inside the documentation, but I haven't been able to fully wrapped my head around it yet.

From what I'm reading it seems like a SyntaxEditor control should have a HighlightingStyle property? For example "this.myEditor.HighlightingStyle"? However this doesn't seen to come up for me.

I also haven't found any concetre example of how to use the Highlighting Style inside the documentation, could I perhaps trouble you into guiding me a little further?

For instance, let's say I have a syntaxEditor control in a specific window, and I'd like this control to be set to a dark theme i'm using. (Let's call said control myEditor)

I go ahead and create a Highlighting Style as follows:

HighlightingStyle darkStyle = new HighlightingStyle("key", "name", MyTheme.ForeColor, MyTheme.BackColor);

How do I go about setting this darkStyle to myEditor?

[Modified 4 years ago]

Posted 4 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Jafran,

An IHighlightingStyle is a single style for a single IClassificationType (e.g. keyword, string).  An IHighlightingStyleRegistry is the registry of highlighting styles (mapping from an IClassificationType to an IHighlightingStyle) that can be used with a SyntaxEditor.

There is a SyntaxEditor.HighlightingStyleRegistry property where you can set a custom IHighlightingStyleRegistry for that single SyntaxEditor instance.  If that property is left null (the default), then the AmbientHighlightingStyleRegistry.Instance (a static instance of IHighlightingStyleRegistry) will be used for the SyntaxEditor.

You can look in the AdornmentsHighlightWord QuickStart's WordHighlightTagger class for an example of registering an IHighlightingStyle.  That example uses the AmbientHighlightingStyleRegistry.Instance, which is the most common scenario.


Actipro Software Support

Posted 4 years ago by Jafran Majeau
Avatar

When I'm looking at the properties of my syntaxEditor instance, there is no HighlightingStyleRegistry (I'm referring here to when I've placed the object in a form to interface with). There's several different option but nothing that has Highlighting anywhere (although there are some reference to the *Highlighting* keyword when I'm browsing this.myEditor.Renderer, but even then the property you mention isn't to be found).

Also I'm not certain what you're referencing to with AdornmentsHighlightWord and all. I can't find mention of it on the doc. In fact I also do not find the syntaxeditor property you mentioned in it either.

I'm assuming that I'm likely misunderstanding your instructions, am I missing something?

Posted 4 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Based on what you are saying, my guess is that you are not on the 2020.1 version as indicated in the original post?  The 2020.1 version is where we ported the newer and much better API design of the WPF version of SyntaxEditor over to the WinForms SyntaxEditor.  Along with that came the SyntaxEditor.HighlightingStyleRegistry property and around 100 samples in the sample project, one of which is the AdornmentsHighlightWord QuickStart sample.


Actipro Software Support

Posted 4 years ago by Jafran Majeau
Avatar

I've double checked that now, I was indeed using an older version. So I've updated and everything, but I still don't see the property you're referring to.

To be faire there are now some properties that have the Highlighting keyword now, such as *BracketHighlightingExclusive*, *BrackHighlightingVisible* and *CurrentLineHighlightingVisible*, however there is still no HighlightingRegistry property to be found.

I'm currently on the 2020.1.0402.

I've tried creating a new SyntaxEditor just in case, but it still doesn't have your mentioned property.

Is there any other reason this might be the case?

Posted 4 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

You might want to double-check your references because I just opened our main v2020.1 SyntaxEditor demo in the sample project and typed "editor.HighlightingStyleRegistry" and it showed up fine in Visual Studio's Intellisense.  Also there is no "BracketHighlightingExclusive" in the 2020.1 version.


Actipro Software Support

The latest build of this product (v24.1.0) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.