Results 1 to 3 of 3

Thread: GradientFill, but it comes up black

  1. #1

    Thread Starter
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Arrow 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:
    1. Public Sub PaintMe( _
    2.     ByVal x As Long, _
    3.     ByVal y As Long, _
    4.     Optional ByVal pfForceRepaint As Boolean = False _
    5. )
    6. '...
    7. Dim lStartColour        As Long
    8. Dim lEndColour          As Long
    9. Dim tvxVertices(1)      As TRIVERTEX
    10. Dim udtGradRect         As GRADIENT_RECT
    11.  
    12.     ' ...
    13.  
    14.         ' paint the background gradient
    15.         lStartColour = GradientColorStart
    16.         lEndColour = GradientColorEnd
    17.  
    18.         RGBToTriplex lStartColour, VarPtr(tvxVertices(0).Red), 2
    19.  
    20.         With tvxVertices(1)
    21.             RGBToTriplex lEndColour, VarPtr(.Red), 2
    22.  
    23.             .x = picBkgd.ScaleWidth
    24.             .y = picBkgd.ScaleHeight
    25.         End With
    26.  
    27.         udtGradRect.LowerRight = 1
    28.  
    29.         GradientFill picBkgd.hDC, _
    30.                      tvxVertices(0), _
    31.                      2, _
    32.                      udtGradRect, _
    33.                      1, _
    34.                      menmGradientDirection
    35.  
    36.     ' ...
    37.  
    38. End Sub

    In case you're wondering (and this bit works):
    VB Code:
    1. Sub RGBToTriplex( _
    2.     ByVal lRGB As Long, _
    3.     ByVal lOutAddress As Long, _
    4.     ByVal cbComponentSize As Long _
    5. )
    6.     RtlMoveMemory ByVal lOutAddress, ByVal VarPtr(lRGB), 1
    7.     RtlMoveMemory ByVal lOutAddress + cbComponentSize, ByVal VarPtr(lRGB) + 1, 1
    8.     RtlMoveMemory ByVal lOutAddress + 2 * cbComponentSize, ByVal VarPtr(lRGB) + 2, 1
    9. End Sub

    The snipped sections are unrelated to the drawing itself.

    Anyone spot anything from the API call that I've missed?

  2. #2
    PowerPoster
    Join Date
    Jul 2001
    Location
    Tucson, AZ
    Posts
    2,166

    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

  3. #3

    Thread Starter
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width