GradientFill, but it comes up black
Trying to use GradientFill to paint a picturebox with a gradient from left to right, but it all comes up black.
Code:
VB Code:
Public Sub PaintMe( _
ByVal x As Long, _
ByVal y As Long, _
Optional ByVal pfForceRepaint As Boolean = False _
)
'...
Dim lStartColour As Long
Dim lEndColour As Long
Dim tvxVertices(1) As TRIVERTEX
Dim udtGradRect As GRADIENT_RECT
' ...
' paint the background gradient
lStartColour = GradientColorStart
lEndColour = GradientColorEnd
RGBToTriplex lStartColour, VarPtr(tvxVertices(0).Red), 2
With tvxVertices(1)
RGBToTriplex lEndColour, VarPtr(.Red), 2
.x = picBkgd.ScaleWidth
.y = picBkgd.ScaleHeight
End With
udtGradRect.LowerRight = 1
GradientFill picBkgd.hDC, _
tvxVertices(0), _
2, _
udtGradRect, _
1, _
menmGradientDirection
' ...
End Sub
In case you're wondering (and this bit works):
VB Code:
Sub RGBToTriplex( _
ByVal lRGB As Long, _
ByVal lOutAddress As Long, _
ByVal cbComponentSize As Long _
)
RtlMoveMemory ByVal lOutAddress, ByVal VarPtr(lRGB), 1
RtlMoveMemory ByVal lOutAddress + cbComponentSize, ByVal VarPtr(lRGB) + 1, 1
RtlMoveMemory ByVal lOutAddress + 2 * cbComponentSize, ByVal VarPtr(lRGB) + 2, 1
End Sub
The snipped sections are unrelated to the drawing itself.
Anyone spot anything from the API call that I've missed?
Re: GradientFill, but it comes up black
Penegate:
I assume GradientColorStart and GradientColorEnd are properties and are globally or modually declared and the values are assigned outside of this proc.??
David
Re: GradientFill, but it comes up black
They return correct RGB values which are then correctly converted into 3 separate Integers by my RGBToTriplex sub. The coordinates are also correct. However all that is painted is blackness.