After much tinkering I managed to get a gradient, but I would like it to go from left to right, from the color chosen as the background it should fade towards white… or at least a color more towards white. The code is this:
' RowTag of ROW
If row >= 0 And row < ListBoxEventi.LastRowIndex+1 Then
Var tag As String = ListBoxEventi.RowTagAt(row)
If tag <> "" Then
Var colori() As String = tag.Split(",")
Dim startColor As Color =Color.FromString(colori(0))
Dim endColor As Color = color.white
Dim p as New Picture(g.Width, g.Height)
Dim samt, eamt As Double
For i As Integer = 0 To p.Width
samt = 1 - (i / p.width)
eamt = i / p.width
p.Graphics.ForeColor = RGB((startColor.Red * samt) + (endColor.Red * eamt), (startColor.Green *samt) + (endColor.Green * eamt), (startColor.Blue * samt) + (endColor.Blue * eamt))
p.Graphics.DrawLine(i,-1,i, p.width+1)
Next
g.DrawPicture(p, 0, 0)
End If
else
g.DrawingColor= color.White 'WHITE
g.FillRectangle(0, 0, g.Width, g.Height)
end if
I’m experimenting, a solution that I might like, in the meantime I’ll try things that I’ve never tried before
I would like to smoke or understand how to go from the color chosen as the background color, to white to apply it to the individual boxes, thus having the first cell with the chosen color, the second with the chosen color minus something and so on, up to the last almost white box.
You will need to calculate the starting and ending gradient colors based on the width of each column and the total width of all columns.
The code you posted already does that in some way.
And as Markus pointed, using LinearGradientBrush will allow for faster drawing as it is handled by the operating system.
Dim startColor As Color = UInt32ToColor(color.FromString(colori(0)))
return error: Eventi.ListBoxEventi.PaintCellBackground, line 11
Parameter “value” expects type UInt32, but this is type Color.
Dim startColor As Color = UInt32ToColor(color.FromString(colori(0))) 'color.FromString(colori(0)) 'Color.FromString(colori(0))
The color read is:&h00ACAC59
Function UInt32ToColor(value As UInt32) As Color
Var alpha As Integer = Bitwise.ShiftRight(Bitwise.BitAnd(value, &hFF000000), 24)
Var red As Integer = Bitwise.ShiftRight(Bitwise.BitAnd(value, &h00FF0000), 16)
Var green As Integer = Bitwise.ShiftRight(Bitwise.BitAnd(value, &h0000FF00), 8)
Var blue As Integer = Bitwise.BitAnd(value, &h000000FF)
Return Color.RGBA(red, green, blue, alpha)
End Function
Looks like the error you posted evaluated UInt32ToColor but your use of color.FromString is wrong as colori(0) is not a valid string that can be used in color.FromString?
there is some exception that I am missing… I read the following values: &h000080FF, &h00ACAC59 and then I get the error: is not a hex color value. Be sure to use the &h prefix.
Here’s how it works:
Dim colorValue As UInt32 = uint32.FromHex(“00ACAC59”) '&h00ACAC59
If I read the value "&h00ACAC59 " as a string from my database, I can’t assign it to colorValue.
I solved:
Dim colorValue As UInt32
if colori(0)<>“” then
colorvalue= uint32.FromHex(colori(0).ReplaceAll(“&h”,“”)) '&h00ACAC59
else
colorvalue=uint32.FromHex(“FFFFFFFF”) 'WHITE
end if
I don’t know if this is the right way, but it works. Suggestions to improve the code?
When pasting code please highlight it and press the </> button, it makes it so much easier. Equally it prevents the " from being turned into curley quotes that don’t work in Xojo.
This works:
Dim colorValue As UInt32
if colori(0)<>"" then
colorvalue= uint32.FromHex(colori(0).ReplaceAll("&h","")) '&h00ACAC59
else
colorvalue=uint32.FromHex("FFFFFFFF") 'WHITE
end if
This doesn’t, due to “” being changed:
Dim colorValue As UInt32
if colori(0)<>“” then
colorvalue= uint32.FromHex(colori(0).ReplaceAll(“&h”,“”)) '&h00ACAC59
else
colorvalue=uint32.FromHex(“FFFFFFFF”) 'WHITE
end if
Separately, colours are not integers. They are a different class. Whilst they seem like a UInt32 they are not. &c is the prefix for a colour constant, &h is a prefix for a numeric constant in hex format. The two are not interchangeable.