5.
Projects using Intrinsic and Professional ActiveX
Controls
4.
Project
for
displaying
color
gradient:
The
program
shown
in
the
figure
7a
is
intended
to
display
a
gradient
of
colors
in a
picture
box.
The
design
window
consists
of
one
picture
box
and
a
command
button
as
shown
in
the
figure
7. On
executing
this
program
you
will
find
a
color
gradient
filling
the
picture
box
as
shown
in
the
figure
8. You
can
try
with
different
starting
and
ending
colors
by
changing
the
RGB
values.

Figure 7
Private
Sub
Command1_Click()
Dim
newcolor
As
Long
Dim
ipixel,
pwidth
As
Integer
Dim
redinc,
greeninc,
blueinc
As
Single
Dim
color1
As
Long,
color2
As
Long
color1
=
RGB(255,
255,
0)
color2
=
RGB(0,
0,
0)
startred
=
getred(color1)
endred
=
getred(color2)
startgreen
=
getgreen(color1)
endgreen
=
getgreen(color2)
startblue
=
getblue(color1)
endblue
=
getblue(color2)
pwidth
=
Picture1.ScaleWidth
redinc
= (endred
-
startred)
/
pwidth
greeninc
= (endgreen
-
startgreen)
/
pwidth
blueinc
= (endblue
-
startblue)
/
pwidth
For
ipixel
= 0
To
pwidth
- 1
newcolor
=
RGB(startred
+
redinc
*
ipixel,
startgreen
+
greeninc
*
ipixel,
startblue
+
blueinc
*
ipixel)
Picture1.Line
(ipixel,
0)-(ipixel,
Picture1.Height
-
1),
newcolor
Next
End
Sub
Function
getred(colorval
As
Long)
As
Integer
getred
=
colorval
Mod
256
End
Function
Function
getgreen(colorval
As
Long)
As
Integer
tgreen
= ((colorval
And
&HFF00FF)
/
256&)
End
Function
Function
getblue(colorval
As
Long)
As
Integer
getblue
= (colorval
And
&HFF0000)
/
(256&
*
256&)
End
Function
Figure
7a

Figure
8
   |