首先,在module文件中加入下列声明语句:
declare function createsolidbrush lib"gdi"(byval crcolor as long) as integer
declare function fillrect lib"user"(byval hdc as integer,lprect as _
rect,byval hbrush as integer)as integer
declare function deleteobject lib"gdi"(byval hobject as integer)as integer
type rect
left as integer
top as integer
right as integer
bottom as integer
endtype
’然后,在窗口的paint事件中加入下列代码:
private sub form_paint()
dim color as integer
dim hbrush as integer
dim oldmode as integer
dim retval as integer
dim stepsize as integer
dim x as integer
dim fillarea as rect
oldmode%=me.scalemode
me.scalemode=3
stepsize%=1+me.scaleheight/80
color%=255
fillarea.left=0
fillarea.right=me.scalewidth
fillarea.top=0
fillarea.bottom=stepsize%
for x%=1 to 80
hbrush%=createsolidbrush (rgb(0,0,color%))
retval%=fillrect(me.hdc,fillarea,hbrush%)
retval%=deleteobject(hbrush%)
color%=color%-4
if color% < 0 then color%=0
fillarea.top=fillarea.bottom
fillarea.bottom=fillarea.bottom+stepsize%
next
me.scalemode=oldmode%
endsub
按f5运行,就会出现一个以从上至下、由浅至深的渐变蓝色为背景的窗口。对上述代码稍加改动,便可制作出各种颜色和水平方向的渐变背景。 |