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
Printable View
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
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
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.
Thanks, though!
How about using a PictureBox instead? You can still use the above method, but just change the beginning line to:
And you would use it like:Code:Sub Dither(vForm As PictureBox)
Code:Dither Picture1
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
The advantage of a PictureBox is that you can draw into it.
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.
For Round Forms::
Worked??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
For Round Corners
Change The cx and cy values for moreCode: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
curvature @ the corners.
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.
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.
Searching for something else I found this nice example for rounding the corners of a form or control with a hWnd.
Thanks!