a我考网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 76|回复: 0

[Visual Basic] 2011年计算机二级VB辅导知识总结(6)

[复制链接]
发表于 2012-7-31 22:10:12 | 显示全部楼层 |阅读模式
  VB调用API制作渐变的窗口背景色: N0 V& u/ C- {. f
  导读:在许多Windows软件的安装程序中,时常可以看到以某种颜色由浅至深的渐变为背景的窗口。使用VB制作这类窗口的方法有不少,而通过调用API函数绘制渐变的窗口背景色,似乎是一种既简单又节省资源的方法。% |+ p6 f. t- {3 ?
  首先,在module文件中加入下列声明语句:/ A' K1 x" c6 F4 S
  Declare Function CreateSolidBrush Lib"GDI"(ByVal _
3 ~' z; O. G% X1 k7 |  crColor As Long) As Integer
0 {6 A5 ^4 y  F2 }2 i1 b- ^3 B; v6 x5 M  Declare Function FillRect Lib"USER"(ByVal hDC As _4 q" g: B: h0 y9 K4 T! r8 o) Y
  Integer,lpRect As RECT,ByVal hBrush As Integer)As Integer+ n/ [5 f( L; Y+ |+ B' j  }
  Declare Function DeleteObject Lib"GDI"(ByVal hObject _
, m# w' I( q( [. q  As Integer)As Integer2 T0 @; S  g3 L  `! f
  Type RECT: w8 a$ X9 m4 C
  left As Integer2 C% N1 ]) F$ R2 e8 _) t
  top As Integer
& D4 L: x+ y8 Y8 p$ ]) V. \8 M) b  right As Integer
' A# l! V) b- _8 [  bottom As Integer
) Y* S% ?5 G: g. ?  EndType: W# n1 j+ g7 P1 y( Q" z5 ~
  然后,在窗口的Paint事件中加入下列代码:
: J/ e5 b$ G6 i" U  Private Sub Form_Paint()- R" C) n) a- x
  Dim Color As Integer
7 V: y2 V6 w7 c6 u9 y/ o( C, A: w  Dim hBrush As Integer
8 B% e) q5 W1 w& E2 `3 g9 A  Dim OldMode As Integer: I5 p+ q$ a% p% H6 \
  Dim RetVal As Integer- D* T/ ]: B5 t
  Dim StepSize As Integer
$ D( O2 k3 I7 p: @' N( T$ t+ X0 E  Dim X As Integer
0 q' O; G: V) ~+ w) A  Dim FillArea As RECT: K+ j% s  ?1 Q! A* n
  OldMode%=Me.ScaleMode
( H' K$ F7 P6 S% w3 m  Me.ScaleMode=3
7 f( d- ~; g/ {8 a/ A/ `2 y# B9 m  StepSize%=1+Me.ScaleHeight/80. q. V" n5 _, m, c$ G
  Color%=255
, @. M' a! D  m  FillArea.left=0
, S; s$ q; }: f9 W! M& m  FillArea.right=Me.ScaleWidth
7 j: w& w; U$ f  FillArea.top=01 }9 p- w( O: i/ ?2 l6 {
  FillArea.bottom=StepSize%
# K+ D' m2 J# z. q( q- s9 w  For X%=1 To 80
8 o. `0 I! [: u! V8 [$ w  hBrush%=CreateSolidBrush (RGB(0,0,Color%))! K, j# J$ J0 P
  RetVal%=FillRect(Me.hDC,FillArea,hBrush%)
2 P7 \. n: c" g  RetVal%=DeleteObject(hBrush%)
, w( _& ?) l& N* P% a  Color%=Color%-45 o0 f# t& `1 a) D+ H
  If Color% $#@60; 0 Then Color%=0  h& I( a6 `5 T* x# h* z3 N$ I
  FillArea.top=FillArea.bottom' F8 G9 o* H7 z7 ?
  FillArea.bottom=FillArea.bottom+StepSize%
$ ]( F0 D6 M4 `: }" E6 W' p, ]5 k  Next
  j9 I* j. q# |) E  Me.ScaleMode=OldMode%8 o9 R9 |0 s0 W5 o; }$ Q3 a0 X
  EndSub
1 I3 Q5 c$ i7 R9 m# k6 |9 e  按F5运行,就会出现一个以从上至下、由浅至深的渐变蓝色为背景的窗口。对上述代码稍加改动,便可制作出各种颜色和水平方向的渐变背景。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Woexam.Com ( 湘ICP备18023104号 )

GMT+8, 2024-6-17 10:53 , Processed in 0.505663 second(s), 22 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表