首页 /编程语言和算法/VB6/ASP
 VB6 用Picture1当进度条的简单方法
昨天 22:15

新建From1(窗体),新建Command1(按钮CommandButton),Picture1(PictureBox),代码:

'The following code demonstrates a simple technique for turning a VB PictureBox into a progress bar.
'Purpose   :    Creates a progress bar from a picture box
'Inputs    :    ProgBar                 The picture box.
'               lPos                    The current position of the progress bar.
'               lMax                    The maximum position of the progress bar.
'Outputs   :    Returns 0 on success, else returns an error code

'Notes     :    Example usuage:
'               DrawProgressBar Picture1, 10  'Draws the progress bar 10% complete
Function DrawProgressBar(ProgBar As PictureBox, lPos As Long, Optional lMax As Long = 100) As Long
    Dim lPercent As Single
    Dim lLenBar As Integer
    On Error GoTo ErrFailed
    If lMax <= 0 Then
        lPercent = 0
    Else
        lPercent = lPos / lMax
    End If
    lLenBar = lPercent * ProgBar.ScaleWidth
    'Fill both sides of the bar (incase a backwards progress bar is required)
    ProgBar.Line (0, 0)-(lLenBar, ProgBar.Height), ProgBar.ForeColor, BF
    ProgBar.Line (lLenBar + 1, 0)-(ProgBar.ScaleWidth, ProgBar.Height), ProgBar.BackColor, BF
    Exit Function
ErrFailed:
    DrawProgressBar = Err.Number
End Function

Private Sub Command1_Click()
    Call DrawProgressBar(Picture1, 20, 100)
End Sub

可以用Picture1当进度条。

 
全部回复(0)
首页 | 电脑版 |