GradientBrush - can't overlay text in correct colour

I’m not sure if this is a bug or a feature…
When I use a linearGradientBrush and then try to draw text afterwards, the text takes on the gradient, rather than its own colour.

Using the gradient example code:

Var linearBrush As New LinearGradientBrush
linearBrush.StartPoint = New Point(0, 0)
linearBrush.EndPoint = New Point(g.Width, g.Height)
linearBrush.GradientStops.Add(New Pair(0, Color.Red))
linearBrush.GradientStops.Add(New Pair(0.4, Color.Yellow))
linearBrush.GradientStops.Add(New Pair(0.7, Color.Magenta))
linearBrush.GradientStops.Add(New Pair(1.0, Color.Blue))

g.Brush = linearBrush
g.FillOval(0, 0, g.Width/2, g.Height/2)

g.DrawingColor = Color.blue
g.FontSize = 20
Var s As String = "The quick brown fox jumps over the lazy dogs tail"
g.DrawText(s,20,30)

I get the following output:

Which means it is ignoring g.drawingColor and applying the gradient to the text - i.e. pretty but unable to write over a gradient.

You forgot to reset the Brush:

g.Brush = linearBrush
g.FillOval(0, 0, g.Width/2, g.Height/2)
g.Brush = Nil

g.DrawingColor = Color.Blue
g.FontSize = 20
Var s As String = "The quick brown fox jumps over the lazy dogs tail"
g.DrawText(s, 20, 30)

Thanks - didn’t see that anywhere in the manual!

1 Like

@Paul_Lefebvre - Maybe you can add a note to the Graphics.Brush Docs.

3 Likes

Someone should file a ticket though. I too would have expected setting a solid color to override the brush (the way that choosing a solid color changes the gradient fill in most photo editing software).

its somehow:

g.DrawingColor =  linearBrush

then it would not have a conflict.

or

g.Brush = Color.blue
without DrawingColor 

or better OOP as example TextShape

A case should be created for this. It may actually be a bug, but even if it needs a doc change a case makes it easier to assign and track since I don’t handle every doc update.

OP had set a solid color after using the brush. Imagine if your photo editing software was still using the previous gradient selection after you’d selected a solid color. Why would it not be a bug?

The framework should work for us, extra steps like “you must nil the brush even after you set a solid color” aren’t good for Rapid App Development.

Update: Changed “even if” to “even after” for clarity in what the issue is.

1 Like

@William_Yu

I completely agree with your position.

Probably the current separation is due to the fact that Color is not a subclass of GraphicsBrush.

1 Like