您的批评和鼓励都是我把编程无限办好的动力! 您编程时遇到困难,或遇到不顺心的事想发发牢骚尽管到这里来吧! 虽然本网力求全面,但也不能包罗万象,这些我筛选出的优秀网站连接就是对本站最好的补充! 学习编程当然也离不开书本了,这里收集大量编程书籍! 编程无限之源码超市,这里收集的代码令你意想不到的全面! 欢迎光临编程网校,这里专门收集VB/CB入门文章及技术文章! 欢迎光临编程无限!
     
       
 
当前位置:中文资料 >> 窗口界面
制作渐变的窗口背景色
  资料类型: 窗口界面 上传时间: 2001-02-21 阅读次数: 2539



制作渐变的窗口背景色

吴斌
  在许多Windows软件的安装程序中,时常可以看到以某种颜色由浅至深的渐变为背景的窗口。使用VB制作这类窗口的方法有不少,而通过调用API函数绘制渐变的窗口背景色,似乎是一种既简单又节省资源的方法。
  首先,在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运行,就会出现一个以从上至下、由浅至深的渐变蓝色为背景的窗口。对上述代码稍加改动,便可制作出各种颜色和水平方向的渐变背景。

推荐给朋友 点 评( 0 ) 返回前页 关闭此页
   
  本类最热文章排名:
  1.制作半透明窗体和形状不规则的窗体
2.自制IE风格按纽控件
3.制作方向按钮
4.字体闪烁
5.制造出透明的Form
6.在菜单中加入图标
7.在VB中制作透明按钮
8.自动改变控件大小
9.用Visual Basic设计更好的用户界面
10.用VB尝试新的界面风格
   
   
  评论:
 
 
 

 

关于本站 版权声明 联系方法
编程无限 V4.1 Copyright © 1999-2008 21code.com

京ICP备05006938号