Colors in datagrid

S

Starbuck

HI

In a previous versino of one of our apps we would store numeric values such
as 16777088 which we used to set the grid colors of a job on a TrueGrid grid
in VB6.


Now in VB.Net we are using the DataGrid and cannot convert these integer
values to System.Drawing.Brush values.

We have tried
NewTextBrush = DirectCast(Colour_Data(0).fcol.ToString,
System.Drawing.Brush)
but this returns a cast error
IS there a way of doing this?
Thanks in advance

Starbuck
 
L

Larry Lard

Starbuck said:
HI

In a previous versino of one of our apps we would store numeric values such
as 16777088 which we used to set the grid colors of a job on a TrueGrid grid
in VB6.
Now in VB.Net we are using the DataGrid and cannot convert these integer
values to System.Drawing.Brush values.

We have tried
NewTextBrush = DirectCast(Colour_Data(0).fcol.ToString,
System.Drawing.Brush)
but this returns a cast error

System.Drawing.Brush is an abstract class, so you must first decide
what concrete type of Brush you want. I'm guessing you want a
SolidBrush. The constructor for SolidBrush wants a Color, so let's go
look at that. We see that Color has a static (class) method called
FromArgb for making Color objects from numbers. Easiest to use is
FromArgb(Integer) where Integer is a complete 32-bit value. The top
byte is the alpha (transparency) value which you probably want as 255
(fully opaque) - the low three bytes are the RGB values you already
have. So we finally have:

Dim NewTextBrush as SolidBrush = _
New SolidBrush(Color.FromArgb(&Hff000000 + Colour_Data(0).fcol))
 
P

Phill. W

Starbuck said:
In a previous versino of one of our apps we would store numeric
values such as 16777088 which we used to set the grid colors of
a job on a TrueGrid grid in VB6.

Now in VB.Net we are using the DataGrid and cannot convert these
integer values to System.Drawing.Brush values.

Create a new SolidBrush from the RGB components of your numeric
colour value. If you're /lucky/, you /might/ get away with ...

Dim z as New SolidBrush( Color.FromArgb( 16777088 ) )

.... but only if the "old" and "new" R, G and B components are in the
same order - I'm not sure they are. If not, you'll have to break your
numeric colour down into the three colour components and use

Dim c as Integer = 16777088
Dim R As Integer = (c And &HFF)
Dim G As Integer = (c And &HFF00) >> 8

Dim B as Integer = ( c And &HFF0000 ) >> 16

Dim z as New SolidBrush( Color.FromArgb( 0, R, G, B ) )

HTH,
Phill W.
 
H

Herfried K. Wagner [MVP]

Starbuck said:
In a previous versino of one of our apps we would store numeric values
such as 16777088 which we used to set the grid colors of a job on a
TrueGrid grid in VB6.

Now in VB.Net we are using the DataGrid and cannot convert these integer
values to System.Drawing.Brush values.

\\\
Dim b As New SolidBrush(ColorTranslator.FromOle(&H...))
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top