VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Form gradient using three only lines of code

by Behrooz Sangani (10 Submissions)
Category: Custom Controls/Forms/Menus
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (4 Votes)

This is how to use gradient colors in a form. You do not need to do anything or write lines of code to add gradient to your forms. Just put the these three lines in Form_Load Sub
Update Note: Thanks for comments, Form_Resize is a better sub if your form is not fixed size

API Declarations
'none

Rate Form gradient using three only lines of code

'=============================================
' Form Gradient
' Add gradient with three lines of code
'=============================================
' Created By: Behrooz Sangani
' Published Date: 27/11/2001
' Email: [email protected]
' Use for free. No obligation!
'=============================================
Private Sub Form_Resize()
'You do not need to do anything or write lines of code _
to add gradient to your forms. Just put the following _
lines in Form_Resize Sub 
'This line is important. You must set the form autoredraw _
to true else nothing would happen. Another problem even _
if you manage to add gradient is you would not be able _
to use labels in your form. Try this and see the results _
labels can't become transparent.
AutoRedraw = True
'This form gradient is a little slow! To help gradient draw _ 
'faster you need to set your form ScaleMode to pixels. 
'This would do great, at least on my PC. 
 
ScaleMode = vbPixels

'Change RGB Numbers in For-Next to have your desired color.
' R=200, G=0, B=255
'Horizental Gradient
For Y = 0 To ScaleHeight
   Line (-1, Y - 1)-(ScaleWidth, Y + 1), RGB(200, 0, 255 - (Y * 255) \ ScaleHeight), B
Next Y
' If you want vertical gradient just reverse the variables. _
Like this:
' For X = 0 To ScaleWidth
'   Line (X - 1, -1)-(X + 1, ScaleWidth), RGB(200, 0, 255 - (X * 255) \ ScaleWidth), B
' Next X
End Sub

Download this snippet    Add to My Saved Code

Form gradient using three only lines of code Comments

No comments have been posted about Form gradient using three only lines of code. Why not be the first to post a comment about Form gradient using three only lines of code.

Post your comment

Subject:
Message:
0/1000 characters