Where in the world is the BackgroundColor?

SyntaxEditor for Windows Forms Forum

Posted 6 years ago by Mike Griffin - Chier Technology Officer, Phurion, LLC
Version: 13.1.0311
Avatar

I am trying to create styles for the SyntaxEditor and I absolutely cannot believe there isn't a BackgroundColor property on the SyntaxEditor, how can this possibly be? It doesn't make sense that we cannot set this? What about those that want to work with a blue or black background like Vibrant Ink?  Can this be set in the XML files or through the API? A little frustrated ...

 

- Mike

[Modified 6 years ago]

Comments (7)

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

Hi Mike,

Everything in SyntaxEditor is rendered with its renderer.  If you didn't set a custom one and want to modify various background area properties, you can do so with lines like this:

var renderer = (VisualStudio2005SyntaxEditorRenderer)editor.RendererResolved;
renderer.TextAreaBackgroundFill = new ActiproSoftware.Drawing.SolidColorBackgroundFill(Color.Black);


Actipro Software Support

Posted 6 years ago by Mike Dempsey - Sr. Developer, Teradata Corp
Avatar

In your language definition XML file:

<Styles>
   <Style Key="DefaultStyle" ForeColor="White" BackColor="Black" />
   <Style Key="KeywordStyle" ForeColor="White" BackColor="Blue" Bold="True" />
   <Style Key= ... />
</Styles>

You can also set other properties such as BorderStyle, etc.

In code you can use:

Dim style As NewHighlightingStyle("DefaultStyle", "Text", Color.Black, Color.White)
myLang.HighlightingStyles.Add(style)

You can also set the background color for a section of code [Span]:

ProtectedSpan = NewReadOnlySpanIndicator("exec", Color.Beige)

(This can of course be the entire editor contents if you want it to be.)

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

Those pieces control the appearance of runs of text, and is separate from the actual control's background rendering (which is done via the renderer I mentioned).  If you are asking how to change the fore/background of specific runs of text, then yes, you'd do it via the styles in the XML or in code.


Actipro Software Support

Posted 6 years ago by Mike Griffin - Chier Technology Officer, Phurion, LLC
Avatar

Actually, I just want to set the background color of the entire syntax editor window. Is there anyway to do that, who would set the background color of just the text but not the background color of the window itself, ie, the entire background whether there is text or not, surely this is possible, otherwise styles would be limited to foreground only. I have never seen a syntax editor that wouldn't let you set the entire background color of the window?

Posted 6 years ago by Mike Griffin - Chier Technology Officer, Phurion, LLC
Avatar

Nevermind, I got it, didn't realize that first example was the answer, thank you ... !!

Posted 6 years ago by Mike Griffin - Chier Technology Officer, Phurion, LLC
Avatar

Uh oh, found an issue, you can set the color like this okay (for the entire window background)

var renderer = (VisualStudio2005SyntaxEditorRenderer)editor.RendererResolved;
renderer.TextAreaBackgroundFill = new ActiproSoftware.Drawing.SolidColorBackgroundFill(Color.Black);

but there is no way to get the background color back out again, ie, from the "renderer.TextAreaBackgroundFill" it's impossible or at least seems that way to get the current background color from the editor.  I've changed your style editor to set the background color just fine by adding another ColorButton ...

[Modified 6 years ago]

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

Hi Mike,

If you try-cast the background fill back to a SolidColorBackgroundFill then you can get the Color off that object.


Actipro Software Support

The latest build of this product (v2018.1 build 0341) was released 7 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.