CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Gradient fill?

  1. #1
    Join Date
    Dec 1999
    Location
    Texas
    Posts
    96

    Gradient fill?

    Does anyone know how to fill a form (or a picture box) with a gradient? Any help would be appreciated?

    Thanks.


  2. #2
    Join Date
    Aug 1999
    Location
    US, Florida
    Posts
    817

    Re: Gradient fill?

    For "sided" gradient

    for z = 0 to 255
    me.Line (Y * 10, height)-(Width, Y * 10), RGB(0, Y, 0), BF
    Y = Y + 1
    next z



    for horizontal
    for z = 0 to 255
    me.Line (Y * 20, Height)-(Width, 0), RGB(0, Y, 0), BF
    Y = Y + 1
    next z



    for vertical
    for z = 0 to 255
    me.Line (0, Height)-(Width, Y * 15), RGB(0, Y, 0), BF
    Y = Y + 1
    next z



    if you want to invert the colors then just use negative values and use scalewidth/scaleheight, you might also want to place a scalemode to pixel
    to create really nice gradients, playy around with variables and you can make really nice effects...like light ray or tunnel, etc.

    Good Luck


  3. #3
    Join Date
    Aug 1999
    Location
    US, Florida
    Posts
    817

    Re: Gradient fill?

    just another example:

    Y2 = me.ScaleHeight
    X2 = me.ScaleWidth
    for z = 0 to 255
    me.Line (0, me.ScaleHeight)-(Y2, Y2), RGB(0, y, 0), B
    me.Line (me.ScaleWidth, Y2)-(Y2, 0), RGB(0, y, 0), B
    y = y + 1
    Y2 = Y2 - 1
    next z





  4. #4
    Join Date
    Dec 1999
    Location
    Austria
    Posts
    17

    Re: Gradient fill?

    and another example:

    [vbcode]
    Private Sub Form_Paint()
    PaintForm Me, 1, 100, 0, 255, 1, 0, -1
    End Sub

    Private Sub PaintForm(FormName As Form, Orientation%, RStart%, GStart%, BStart%, RInc%, GInc%, BInc%)
    ' This routine does NOT use API calls
    On Error Resume Next
    Dim x As Integer, y As Integer, z As Integer, Cycles As Integer
    Dim R%, G%, B%
    R% = RStart%: G% = GStart%: B% = BStart%
    ' Dividing the form into 100 equal parts
    If Orientation% = 0 Then
    Cycles = FormName.ScaleHeight \ 100
    Else
    Cycles = FormName.ScaleWidth \ 100
    End If
    For z = 1 To 100
    x = x + 1
    Select Case Orientation
    Case 0: 'Top to Bottom
    If x > FormName.ScaleHeight Then Exit For
    FormName.Line (0, x)-(FormName.Width, x + Cycles - 1), RGB(R%, G%, B%), BF
    Case 1: 'Left to Right
    If x > FormName.ScaleWidth Then Exit For
    FormName.Line (x, 0)-(x + Cycles - 1, FormName.Height), RGB(R%, G%, B%), BF
    End Select
    x = x + Cycles
    R% = R% + RInc%: G% = G% + GInc%: B% = B% + BInc%
    If R% > 255 Then R% = 255
    If R% < 0 Then R% = 0
    If G% > 255 Then G% = 255
    If G% < 0 Then G% = 0
    If B% > 255 Then B% = 255
    If B% < 0 Then B% = 0
    Next z
    End Sub
    [vbcode]


  5. #5
    Join Date
    Dec 1999
    Location
    Austria
    Posts
    17

    Re: Gradient fill?

    and another example:

    Private Sub Form_Paint()
    PaintForm Me, 1, 100, 0, 255, 1, 0, -1
    End Sub

    Private Sub PaintForm(FormName As Form, Orientation%, RStart%, GStart%, BStart%, RInc%, GInc%, BInc%)
    ' This routine does NOT use API calls
    On Error Resume Next
    Dim x As Integer, y As Integer, z As Integer, Cycles As Integer
    Dim R%, G%, B%
    R% = RStart%: G% = GStart%: B% = BStart%
    ' Dividing the form into 100 equal parts
    If Orientation% = 0 Then
    Cycles = FormName.ScaleHeight \ 100
    Else
    Cycles = FormName.ScaleWidth \ 100
    End If
    For z = 1 To 100
    x = x + 1
    Select Case Orientation
    Case 0: 'Top to Bottom
    If x > FormName.ScaleHeight Then Exit For
    FormName.Line (0, x)-(FormName.Width, x + Cycles - 1), RGB(R%, G%, B%), BF
    Case 1: 'Left to Right
    If x > FormName.ScaleWidth Then Exit For
    FormName.Line (x, 0)-(x + Cycles - 1, FormName.Height), RGB(R%, G%, B%), BF
    End Select
    x = x + Cycles
    R% = R% + RInc%: G% = G% + GInc%: B% = B% + BInc%
    If R% > 255 Then R% = 255
    If R% < 0 Then R% = 0
    If G% > 255 Then G% = 255
    If G% < 0 Then G% = 0
    If B% > 255 Then B% = 255
    If B% < 0 Then B% = 0
    Next z
    End Sub



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

Featured