• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

创建setup类型的进度条

发布: 2007-7-14 20:28 | 作者: 佚名    | 来源: 网络转载     | 查看: 16次 | 进入软件测试论坛讨论

领测软件测试网 新建一个工程

增加一个picture box和command button

加入下面的代码:
Dim tenth As Long
'条件编译
#If Win32 Then
Private Declare Function BitBlt Lib "gdi32" _
(ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, _
ByVal nWidth As Long, ByVal nHeight As Long, _
ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, _
ByVal dwRop As Long) As Long
#Else
Private Declare Function BitBlt Lib "GDI" (ByVal hDestDC As _
Integer, ByVal x As Integer, ByVal y As Integer, ByVal nWidth _
As Integer, ByVal nHeight As Integer, ByVal hSrcDC As Integer, _
ByVal xSrc As Integer, ByVal ySrc As Integer, ByVal dwRop As _
Long) As Integer
#End If

Sub UpdateStatus(FileBytes As Long)
'--------------------------------------------------------------------
' 更新Picture1 status bar
'--------------------------------------------------------------------
    Static progress As Long
    Dim r As Long
    Const SRCCOPY = &HCC0020
    Dim Txt$
    progress = progress + FileBytes
    If progress > Picture1.ScaleWidth Then
        progress = Picture1.ScaleWidth
    End If
    Txt$ = Format$(CLng((progress / Picture1.ScaleWidth) * 100)) + "%"
    Picture1.Cls
    Picture1.CurrentX = _
    (Picture1.ScaleWidth - Picture1.TextWidth(Txt$)) \ 2
    Picture1.CurrentY = _
    (Picture1.ScaleHeight - Picture1.TextHeight(Txt$)) \ 2
    Picture1.Print Txt$
    Picture1.Line (0, 0)-(progress, Picture1.ScaleHeight), _
    Picture1.ForeColor, BF
    r = BitBlt(Picture1.hDC, 0, 0, Picture1.ScaleWidth, _
        Picture1.ScaleHeight, Picture1.hDC, 0, 0, SRCCOPY)
End Sub

Private Sub Command1_Click()
    Picture1.ScaleWidth = 109
    tenth = 10
    For i = 1 To 11
        Call UpdateStatus(tenth)
        x = Timer
        While Timer < x + 0.75
            DoEvents
        Wend
    Next
End Sub

Private Sub Form_Load()
    Picture1.FontBold = True
    Picture1.AutoRedraw = True
    Picture1.BackColor = vbWhite
    Picture1.DrawMode = 10
    Picture1.FillStyle = 0
    Picture1.ForeColor = vbBlue
End Sub



F5 运行, 点击 Command1就可以看到效果. 

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网