Posted 17 years ago by Ernst
Avatar
I want to ensure my application works in any Windows color schema and I'm having problems with the Syntax Editor. I just want the editor to keep white background for any color schema otherwise syntax highlights may become invisible.

The Renderer property is not editable in the Visual Studio Designer and assigning one of the default renderers doesn't help. It is hard to edit renderer properties manually, so I'm hoping there is a simpler solution.

Thanks,
Ernst

Comments (3)

Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Actually there is a verb to add a control-specific renderer in the designer then you can edit the settings on that. It will create a VisualStudio2005SyntaxEditorRenderer by default.

However if you'd like to edit the settings for all SyntaxEditors, you want to access the global renderer instead. Instead of creating any control-specific renderers (in the Renderer property), after at least one SyntaxEditor has been created (which registers the global renderer), you can do this sort of code:
VisualStudio2005SyntaxEditorRenderer globalRenderer = (VisualStudio2005SyntaxEditorRenderer)editor.RendererResolved;
globalRenderer.TextAreaBackgroundFill = new ActiproSoftware.Drawing.SolidColorBackgroundFill(Color.White);


Actipro Software Support

Posted 17 years ago by Ernst
Avatar
This doesn't work. When user changes windows colors the color schema seems to be reset to the default one.

So if I set syntaxEditor background color to 'X' and change color schema to "windows classic high contrast black" then the background becomes black no matter what 'X' is. Then if I go back to Windows XP schema the background is still not 'X' unless 'X' is white.

Thanks,
Ernst
Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Ok, what is happening here is that the color scheme change causes the background fills to be reset on the renderer. What you need to do is make a custom renderer class "MyRenderer" that inherits VisualStudio2005SyntaxEditorRenderer, override the Reset/ShouldSerialize methods for the TextAreaBackgroundFill property and then install that custom renderer as the default global one.

So method overrides like this:
public override void ResetTextAreaBackgroundFill() {
    this.TextAreaBackgroundFill = new SolidColorBackgroundFill(Color.White);
}
public override bool ShouldSerializeTextAreaBackgroundFill() {
    return (this.TextAreaBackgroundFill == null) || !this.TextAreaBackgroundFill.Equals(new SolidColorBackgroundFill(Color.White));
}
Next we need a factory class that creates your custom renderer class:
/// <summary>
/// Provides a factory for creating an <see cref="ISyntaxEditorRenderer"/>.
/// </summary>
public class MyRendererFactory : IUIRendererFactory {
    
    /// <summary>
    /// Creates a renderer.
    /// </summary>
    /// <returns>The <see cref="IUIRenderer"/> that was created.</returns>
    IUIRenderer IUIRendererFactory.CreateRenderer() {
        return new MyRenderer();
    }

}
Then in your app startup code (before a form executes), register your renderer factory like this:
ActiproSoftware.WinUICore.UIRendererManager.RegisterRendererFactory(typeof(ISyntaxEditorRenderer), new MyRendererFactory(), true);


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.