LinearGradients in DataGridColoredTextBoxColumn

  • Thread starter Thread starter Rob Oldfield
  • Start date Start date
R

Rob Oldfield

I'm using the DataGridColoredTextBoxColumn class (the VB version) -

http://msdn.microsoft.com/smartclient/community/wffaq/ctrlsp.aspx#4umuvlol

to colour cells in a datagrid on a windows form (VS 2003) and, for the most
part, it's working fine. One slight issue though...

If I use

backBrush = New LinearGradientBrush(bounds, Color.White, Color.Blue,
LinearGradientMode.Horizontal)

then the left hand edge of the cell has a vertical solid blue line down it.
And if I use

backBrush = New LinearGradientBrush(bounds, Color.Blue, Color.White,
LinearGradientMode.Horizontal)

then the left hand edge has a white vertical line down it.

In effect, the colour at the right hand edge of the box is 'wrapping' round
and reappearing as a single line down the left.

Does anyone know what is causing this, and what I can do to fix it?
 
This is a known issue with the linear gradient brush. Make the bounds of the
brush slightly larger (1 pixel) than the area you wish to paint into.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
Thanks for the info... but I can't figure out how to do that.

Given that I have...

backBrush = New LinearGradientBrush(bounds, Color.White, Color.LightBlue,
LinearGradientMode.Horizontal)

and then

MyBase.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight)

....then where do I make that change? I've tried defining a new
system.drawing.rectangle and then setting it's properties by

Dim b As New System.Drawing.Rectangle
b.Left = bounds.Left - 1

but it tells me that b is read only.
 
Perfect. Many thanks.


Bob Powell said:
dim b as new rectangle(bounds.left-1, bounds.top-1,bounds.width+2,
bounds.height+2)


--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
Back
Top