a我考网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 79|回复: 0

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

[复制链接]
发表于 2012-7-31 22:10:12 | 显示全部楼层 |阅读模式
  VB调用API制作渐变的窗口背景色% l1 L- z6 b. y
  导读:在许多Windows软件的安装程序中,时常可以看到以某种颜色由浅至深的渐变为背景的窗口。使用VB制作这类窗口的方法有不少,而通过调用API函数绘制渐变的窗口背景色,似乎是一种既简单又节省资源的方法。
2 Y; Y2 n% e$ M/ R' k! d" G2 A  首先,在module文件中加入下列声明语句:7 @: I+ v- C4 B6 K$ ~
  Declare Function CreateSolidBrush Lib"GDI"(ByVal _
0 C$ k$ x5 l# y! _) r% \8 S' [" w' R  crColor As Long) As Integer. T! T  g0 z; O8 I; I0 \$ O$ n7 V
  Declare Function FillRect Lib"USER"(ByVal hDC As _
/ b4 ~$ j. p7 l5 y) Q  Integer,lpRect As RECT,ByVal hBrush As Integer)As Integer0 S1 X+ P+ ]( ?- W) V0 L# Y2 @
  Declare Function DeleteObject Lib"GDI"(ByVal hObject _/ L' f5 ^* d7 @* L* \0 q; D
  As Integer)As Integer
! K/ p- _+ w5 e6 d; }  Type RECT
& O* j3 g  K' q9 s  left As Integer- n; E5 e- N% z- _0 r
  top As Integer
1 w+ s4 Z  s% w1 F" e! Y3 o  right As Integer2 S. w: p. H0 }. z& U* \" p2 o6 e* X
  bottom As Integer, k" X- Y9 {5 v- n; I* _
  EndType
$ o3 n7 u4 x" U2 T  然后,在窗口的Paint事件中加入下列代码:
, Y2 ^) j/ I0 Y  Private Sub Form_Paint()6 h  s0 N) Z$ d$ R- `
  Dim Color As Integer+ x2 }' s4 A2 J
  Dim hBrush As Integer& `: L: H: J8 P  {5 u4 p& t. S
  Dim OldMode As Integer
2 ^) A: h6 _3 P  Dim RetVal As Integer
( [  ]) R5 Y) V' l$ ~5 _, n  Dim StepSize As Integer; V: d* a! x* S! I0 N, Q
  Dim X As Integer% a0 w6 Y* N, T3 G; b+ c
  Dim FillArea As RECT
  H3 u4 N3 p' ~7 B  OldMode%=Me.ScaleMode
: w' ?% q6 n( k3 J" U, s  Me.ScaleMode=3- W0 y  y. ~9 k( A, f
  StepSize%=1+Me.ScaleHeight/800 @; i. M) F- G! g1 ^+ G2 ~3 O1 @
  Color%=255
; w8 T0 }3 Q0 c( ]+ z# X3 {2 j% C$ W  FillArea.left=0& p  R/ S* f* H9 I" x+ n9 H
  FillArea.right=Me.ScaleWidth1 y! v) V  G# ~( A( d
  FillArea.top=0
! k) D: r. F! _$ y! C8 L& O  FillArea.bottom=StepSize%3 k. `9 y0 U6 N5 ?5 v
  For X%=1 To 80
) g5 ]6 I2 u4 U" k' |1 h, `  hBrush%=CreateSolidBrush (RGB(0,0,Color%))
1 A( |% S- D, }8 }  RetVal%=FillRect(Me.hDC,FillArea,hBrush%)/ L* ~7 S7 o9 Z, \
  RetVal%=DeleteObject(hBrush%)3 C* F8 ^' u  o. E5 K- r
  Color%=Color%-4; E6 R2 X: K( \9 C$ X
  If Color% $#@60; 0 Then Color%=0
! ^0 ~- z' j1 P" m8 ?1 i- b4 Y% X  FillArea.top=FillArea.bottom; u$ s# O; l3 C4 T, o, G
  FillArea.bottom=FillArea.bottom+StepSize%
+ h! @1 U+ G# Z% D( U0 _  Next
5 N* m3 u  f; w( X  c8 x6 C: `! I  Me.ScaleMode=OldMode%  F6 W: ^. k2 e. W+ ]
  EndSub* g; ?+ ~) s6 ?/ d4 v/ g
  按F5运行,就会出现一个以从上至下、由浅至深的渐变蓝色为背景的窗口。对上述代码稍加改动,便可制作出各种颜色和水平方向的渐变背景。
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-6-26 15:56 , Processed in 0.538557 second(s), 21 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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