|
-
Nov 5th, 2003, 03:07 PM
#1
Thread Starter
Supreme User
Draw Gradients [CODE INSIDE]
Simple to use, short in code and doesnt take much memory when loading. Set your form to AutoRedraw True, then add this code in the Declarations:
VB Code:
Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Then add this code:
VB Code:
Public Function gradient(obj As Object, col1, col2)
Dim p As POINTAPI
oldsc = obj.ScaleMode
obj.ScaleMode = 3
r = (col1 And &HFF&)
g = (col1 And &HFF00&) / &H100&
b = (col1 And &HFF0000) / &H10000
r2 = (col2 And &HFF&)
g2 = (col2 And &HFF00&) / &H100&
b2 = (col2 And &HFF0000) / &H10000
sw = obj.ScaleWidth
dr = (r2 - r) / sw
dg = (g2 - g) / sw
db = (b2 - b) / sw
obj.Cls
For i = 1 To sw
r = r + dr
g = g + dg
b = b + db
y = obj.ScaleHeight
obj.ForeColor = RGB(CInt(r), CInt(g), CInt(b))
MoveToEx Form1.hdc, i, 0, p
LineTo obj.hdc, i, y
Next i
obj.ScaleMode = oldsc
End Function
And finally add this:
VB Code:
Private Sub Form_Resize()
gradient Form1, Color1, Color2
End Sub
Enjoy;)
-
Nov 27th, 2003, 08:28 AM
#2
Thread Starter
Supreme User
You can also make your own custom colored gradients, make a command button, and add a Dialog1 and Dialog2 control then.
Private Sub Command1_Click()
Dialog1.ShowColor
Dialog2.ShowColor
gradient Me, Dialog1.Color, Dialog2.Color
End Sub
Im away from vb so this may be wrong. But the idea is there!
-
Nov 29th, 2003, 07:59 AM
#3
New Member

There is actually an API function that draws gradient rectangles; I found this out when making the bsGradientLabel control.
http://www.mentalis.org/apilist/GradientFillRect.shtml
-
Nov 29th, 2003, 08:02 AM
#4
Thread Starter
Supreme User
Yeah, that site has tons of API codes
-
Nov 29th, 2003, 11:33 PM
#5
MadBoy, I edited your post and checked the Disable Smilies in This Post button so that the &) characters don't get translated to
-
Nov 30th, 2003, 12:19 PM
#6
Thread Starter
Supreme User
Cheers marty, i forgot you could do that.
-
Mar 30th, 2004, 11:25 AM
#7
Thread Starter
Supreme User
-
Mar 30th, 2004, 05:12 PM
#8
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|