我想让显示进度的百分比在进度条中间显示,应该怎样写呀???
我的代码如下:Private Sub Command1_Click()
Timer1.Enabled = True
Progress1.Percent = 0
Progress1.Refresh
End SubPrivate Sub Form_Load()
Progress1.Percent = 0
Progress1.Refresh
Timer1.Enabled = False
End SubPrivate Sub Timer1_Timer()
Progress1.Percent = Progress1.Percent + 1
Progress1.Refresh
'我只能让他显示在这里。
lblloading.Caption = "程序加载中..: " & Progress1.Percent & "%"
Progress1.Refresh
If Progress1.Percent = 100 Then
Timer1.Enabled = False
lblloading.Caption = "加载完成!"
End If
End Sub
我的代码如下:Private Sub Command1_Click()
Timer1.Enabled = True
Progress1.Percent = 0
Progress1.Refresh
End SubPrivate Sub Form_Load()
Progress1.Percent = 0
Progress1.Refresh
Timer1.Enabled = False
End SubPrivate Sub Timer1_Timer()
Progress1.Percent = Progress1.Percent + 1
Progress1.Refresh
'我只能让他显示在这里。
lblloading.Caption = "程序加载中..: " & Progress1.Percent & "%"
Progress1.Refresh
If Progress1.Percent = 100 Then
Timer1.Enabled = False
lblloading.Caption = "加载完成!"
End If
End Sub
把以下代码拷到窗口中
Dim i As SinglePrivate Sub UpdateStatus(pic As PictureBox, ByVal sngPercent As Single, Optional ByVal fBorderCase As Boolean = False)
Dim strPercent As String
Dim intX As Integer
Dim intY As Integer
Dim intWidth As Integer
Dim intHeight As Integer 'For this to work well, we need a white background and any color foreground (blue)
Const colBackground = &HFFFFFF ' white
Const colForeground = &H800000 ' dark blue pic.ForeColor = colForeground
pic.BackColor = colBackground '
'Format percentage and get attributes of text
'
Dim intPercent
intPercent = Int(100 * sngPercent + 0.5) 'Never allow the percentage to be 0 or 100 unless it is exactly that value. This
'prevents, for instance, the status bar from reaching 100% until we are entirely done.
If intPercent = 0 Then
If Not fBorderCase Then
intPercent = 1
End If
ElseIf intPercent = 100 Then
If Not fBorderCase Then
intPercent = 99
End If
End If strPercent = Format$(intPercent) & "%"
intWidth = pic.TextWidth(strPercent)
intHeight = pic.TextHeight(strPercent) '
'Now set intX and intY to the starting location for printing the percentage
'
intX = pic.Width / 2 - intWidth / 2
intY = pic.Height / 2 - intHeight / 2 '
'Need to draw a filled box with the pics background color to wipe out previous
'percentage display (if any)
'
pic.DrawMode = 13 ' Copy Pen
pic.Line (intX, intY)-Step(intWidth, intHeight), pic.BackColor, BF '
'Back to the center print position and print the text
'
pic.CurrentX = intX
pic.CurrentY = intY
pic.Print strPercent '
'Now fill in the box with the ribbon color to the desired percentage
'If percentage is 0, fill the whole box with the background color to clear it
'Use the "Not XOR" pen so that we change the color of the text to white
'wherever we touch it, and change the color of the background to blue
'wherever we touch it.
'
pic.DrawMode = 10 ' Not XOR Pen
If sngPercent > 0 Then
pic.Line (0, 0)-(pic.Width * sngPercent, pic.Height), pic.ForeColor, BF
Else
pic.Line (0, 0)-(pic.Width, pic.Height), pic.BackColor, BF
End If pic.Refresh
End SubPrivate Sub Form_Load()
picStatus.AutoRedraw = True
End SubPrivate Sub Timer1_Timer()
i = i + 0.1
UpdateStatus picStatus, i, True
If i >= 1 Then i = 0
End Sub