Results 1 to 13 of 13

Thread: Shading a Shape

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2000
    Posts
    208
    Hi there . . .

    I've got some shapes on my form, and instead of a solid background color, I'd like to have it shaded -- (ie, dark blue on top, light blue at the bottom, faded into each other).

    Any suggestions?

    Elizabeth

  2. #2
    Megatron
    Guest
    You don't need a shape for this:
    Code:
    Sub Dither(vForm As Form)
        Dim intLoop As Integer
        vForm.DrawStyle = vbInsideSolid
        vForm.DrawMode = vbCopyPen
        vForm.ScaleMode = vbPixels
        vForm.DrawWidth = 2
        vForm.ScaleHeight = 256
        For intLoop = 0 To 255
            vForm.Line (0, intLoop)-(Screen.Width, intLoop - 1), RGB(0, 0, 255 - intLoop), B
        Next intLoop
    End Sub
    
    Private Sub Form_Activate()
        AutoRedraw = True
        Dither Me
    End Sub
    
    Private Sub Form_Resize()
        Dither Me
    End Sub

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2000
    Posts
    208
    Sorry I wasn't clear.

    I only want little areas of the form to be shaded. Not the whole form.

    Originally I had just a shape on the form with a fill color, but now they've decided they'd like to see it with a gradient color instead of a solid.

    I've been playing around with images in the meantime.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Oct 2000
    Posts
    208
    Thanks, though!

  5. #5
    Megatron
    Guest
    How about using a PictureBox instead? You can still use the above method, but just change the beginning line to:
    Code:
    Sub Dither(vForm As PictureBox)
    And you would use it like:
    Code:
    Dither Picture1

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Oct 2000
    Posts
    208
    Any suggestion on how to get rounded corners? That's what the boss liked about the shape, was the rounded corners.

    Would there be an advantage to using a filled picturebox instead of an image?

    Thanks, Elizabeth

  7. #7
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    The advantage of a PictureBox is that you can draw into it.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  8. #8
    Megatron
    Guest
    In other words, it's an actual window, whereas an Image is not. An Image is simply drawn onto the DC of the parent window, so the advantage is that it consumes less resources.

  9. #9
    Addicted Member KrishnaSantosh's Avatar
    Join Date
    Feb 2001
    Location
    Coimbatore
    Posts
    210
    For Round Forms::

    Code:
    'In a module 
    ' or in a form(Change to private)
    Public Declare Function CreateEllipticRgn Lib "gdi32" Alias "CreateEllipticRgn" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    
    Public Declare Function SetWindowRgn Lib "user32" Alias "SetWindowRgn" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
    
    ' In The Form
    
    Private Sub Form_Load( )
     Dim lRgn As Long
     lRgn=CreateEllipticRgn(0,0,Me.Width/Screen.TwipsPerPixelX,Me.Height/Screen.TwipsPerPixelY)
     SetWindowRgn Me.hWnd,lRgn,True
    End Sub
    Worked??

  10. #10
    Addicted Member KrishnaSantosh's Avatar
    Join Date
    Feb 2001
    Location
    Coimbatore
    Posts
    210
    For Round Corners

    Code:
    Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
    
    Private Declare Function CreateRoundRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long
    
    Private Sub Form_Load()
        cx = 50
        cy = 50
        lrgn = CreateRoundRectRgn(0, 0, Me.Width / Screen.TwipsPerPixelX, Me.Height / Screen.TwipsPerPixelY, cx, cy)
        SetWindowRgn hWnd, lrgn, 1
    End Sub
    Change The cx and cy values for more
    curvature @ the corners.

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Oct 2000
    Posts
    208
    KrishnaSantosh --

    Yup, it works, and it might come in handy in the future. But I'm not looking for a form with rounded edges, I'd like a shape with rounded edges inside my form.

    Mega -- so it sounds like for my purposes, an image would be better? It's lighter, and I don't really need to draw on it. A static image is fine for what I need to do.

  12. #12
    Addicted Member KrishnaSantosh's Avatar
    Join Date
    Feb 2001
    Location
    Coimbatore
    Posts
    210
    To shade a control inside the form, just change the
    SetWindowRgn to the hWnd of the Control.

    Note: Image box doesn't have an hWnd. So try using
    picture box as it is much functional that image,
    though it costs you something, in terms of
    memory.

  13. #13
    Hyperactive Member Steve Stunning's Avatar
    Join Date
    Jul 1999
    Location
    Fairfax, Virginia
    Posts
    314
    Searching for something else I found this nice example for rounding the corners of a form or control with a hWnd.

    Thanks!
    Steve Stunning

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