silver_shot
10-25-2004, 04:55 PM
I found this excellent example http://www.ilook.fsnet.co.uk/vb/vbgrad.htm which can gradient a picture box from your specified colour to black. The only problem with it is that I don't want it to fade to black, I would like to fade it to a colour I choose... I have seen this example where you decide the colours faded but it doesn't work for a picture box and I can't see how to adapt it...
Thanks for help
silver_shot
10-25-2004, 04:58 PM
Answering my own question I just did it... I change it from frm as Form to Object as TheObject and it's all working... if someone would like me to post the example I'm glad to do it
Silver
evil13
10-25-2004, 08:43 PM
It sound interesting, post the example to share everyone your knowledge!
silver_shot
10-26-2004, 05:14 PM
It sound interesting, post the example to share everyone your knowledge!
I didn't write this code... I only changed a little bit for it to work on objetcs:
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function FillRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
Private Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Function SafeDiv(X1 As Double, X2 As Double) As Double
If X2 = 0 Then SafeDiv = 0 Else SafeDiv = X1 / X2
End Function
Private Sub PaintGradient(TheObject As Object, Red1 As Integer, Green1 As Integer, Blue1 As Integer, Red2 As Integer, Green2 As Integer, Blue2 As Integer)
Dim WinRect As RECT
Dim ColorRect As RECT
Dim Y As Long
Dim hBrush As Long
Dim hPrevBrush As Long
Dim DivValue As Double
Dim CurrRed As Integer
Dim CurrGreen As Integer
Dim CurrBlue As Integer
GetClientRect TheObject.hwnd, WinRect
For Y = WinRect.Top To WinRect.Bottom
DivValue = SafeDiv((WinRect.Bottom - WinRect.Top), (Y - WinRect.Top))
CurrRed = Red1 + SafeDiv((Red2 - Red1), DivValue)
CurrGreen = Green1 + SafeDiv((Green2 - Green1), DivValue)
CurrBlue = Blue1 + SafeDiv((Blue2 - Blue1), DivValue)
SetRect ColorRect, WinRect.Left, Y, WinRect.Right, Y + 1
hBrush = CreateSolidBrush(RGB(CurrRed, CurrGreen, CurrBlue))
hPrevBrush = SelectObject(TheObject.hdc, hBrush)
FillRect TheObject.hdc, ColorRect, hBrush
SelectObject TheObject.hdc, hPrevBrush
DeleteObject hBrush
Next
Me.Refresh
End Sub
Private Sub Form_Load()
PaintGradient Picture1, 255, 255, 255, 224, 230, 248 'this calls the sub to paint the gradient of picture1. the first 3 sets of digits choose the top colour, the last 3 sets choose the bottom colour.
End Sub
I like this one better, because you can choose any angle gradient (instead of just using 90 degree increments):
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=6154&lngWId=1
Here's the screenshot of what it looks like (one angle):
http://www.planet-source-code.com/upload_PSC/screenshots/PIC2000226556295795.jpg