VB编写进度条已经发展很久了,也有很多好方法。
VB自带的进度条很难看,一般不用,要用的话,代码如下:
Private Sub Command1_Click()
Dim counter As Integer
Dim workarea(25000) As String
ProgressBar1.Min = LBound(workarea)
ProgressBar1.Max = UBound(workarea)
ProgressBar1.Visible = True
ProgressBar1.Value = ProgressBar1.Min
For counter = LBound(workarea) To UBound(workarea)
workarea(counter) = "initial value" & counter
ProgressBar1.Value = counter
Next counter
End Sub
各位看官,直接看下面:
Text实现进度条:
Option Explicit
Dim i As Integer
Private Sub Form_Load()
Timer1.Enabled = True
Text2.Width = (Form1.Width / 100)
End Sub
Private Sub Timer1_Timer()
'进度条设置
Text2.Width = Text2.Width + (Form1.Width / 100)
If (Text2.Width / Form1.Width) > 1 Then
Form2.Show '载入主画面
Unload Me
End If
End Sub
Image进度条:
Option Explicit
Dim i As Integer
Private Sub Form_Load()
JDT.Top = Lab.Top
JDT.Width = (Lab.Width / 100)
End Sub
Private Sub Timer1_Timer()
'进度条设置
JDT.Width = JDT.Width + (Lab.Width / 100)
If (JDT.Width / Lab.Width) > 1 Then
Form1.Show '载入主画面
Unload Me
End If
End Sub
那么更换N个image就会有N个进度条演示,下面示图,大家自己试试。
有看官马上问:那怎么显示百分比呢
这个不难,百分比代码:
'加一个timer和一个label
'From:yxmhero1989.blog.163
'Author:Minghacker
Dim b As Boolean
Dim i As Integer
Private Sub Timer1_Timer()
If b Then i = i + 1
If Not b Then i = i - 1
If i > 100 Then i = 100: b = False
If i < 0 Then i = 0: b = True
Label1.Caption = CStr(i) + " %"
End Sub
Private Sub Form_Load()
b = True
i = 0
End Sub
这样两个配合,进度条加进度百分比,看客们该是熟悉了吧?具体时间和进度协调要看你的计算了。
vb所有代码Picture进度条:
'例子需以下控件: 'Command1、Command2、Picture1:都采用默认属性设置
Dim ctEsc As Boolean
Private Sub Form_Load()
'初始化控件
Picture1.AutoRedraw = True
Command1.Caption = "滚动条例子": Command2.Caption = "取消"
End Sub
Private Sub Command1_Click()
Dim I As Long, S As Long
ctEsc = False
S = 1000
For I = 1 To S
Me.Cls: Me.Print "显示:" & I
JinDuTiao I / S, "0.0" '显示进度条:进度,显示格式(即小数数位)
DoEvents
If ctEsc Then Me.Print "已取消": Exit Sub
Next
Me.Print "完毕"
End Sub
Private Sub Command2_Click()
ctEsc = True
End Sub
Private Sub JinDuTiao(Bi As Single, Optional nFormt As String = "0")
Dim W As Long, H As Long, nStr As String
Static UpBi As String
nStr = Format(Bi * 100, nFormt)
If Val(nStr) >= "100" Then nStr = 100
If UpBi = nStr Then Exit Sub
UpBi = nStr
W = Picture1.ScaleWidth: H = Picture1.ScaleHeight
Picture1.Cls
Picture1.DrawMode = 13
nStr = nStr & " %"
Picture1.CurrentX = (W - Picture1.TextWidth(nStr)) * 0.5
Picture1.CurrentY = (H - Picture1.TextHeight(nStr)) * 0.5
Picture1.Print nStr
Picture1.DrawMode = 14
Picture1.Line (0, 0)-(W * Bi, H), &HFF0000, BF
Picture1.Refresh
End Sub
shape进度条:
'例子需以下控件: 'Command1、Command2、Label1、Label2、Shape1:都采用默认属性设置
Dim ctEsc As Boolean
Private Sub Form_Load()
'初始化控件
Command1.Caption = "滚动条例子": Command2.Caption = "取消"
Label1.BorderStyle = 1: Label1.Caption = "0%"
Label1.Alignment = 2: Label1.Height = Me.TextHeight("A") * 1.5
Shape1.FillStyle = 0: Shape1.FillColor = &HFF0000: Shape1.DrawMode = 14
Shape1.Move Label1.Left, Label1.Top, 30, Label1.Height - Screen.TwipsPerPixelY * 2
Shape1.ZOrder
End Sub
Private Sub Command1_Click()
Dim I As Long, S As Long
ctEsc = False
S = 1000
For I = 1 To S
Me.Cls: Me.Print "显示:" & I
JinDuTiao I / S, "0.0" '显示进度条:进度,显示格式(即小数数位)
DoEvents
If ctEsc Then Me.Print "已取消": Exit Sub
Next
Me.Print "完毕"
End Sub
Private Sub Command2_Click()
ctEsc = True
End Sub
Private Sub JinDuTiao(Bi As Single, Optional nFormt As String = "0")
Label1.Caption = Int(Bi * 100) & "%"
Shape1.Width = Bi * Label1.Width
End Sub
简单的就介绍至此,更简单的提示下,用控件,呵呵,这个最爽,可以做出各种效果。彩到炫死
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论