----------------------------------------------------------------------------------------------------------------------------------------------- 本文提示:《用VB做个漂亮的进度条(2)》是本站编辑们为广大网友精选的实用文章,本文阐述了关于文章的相关理论,相对来说专业性强,但是本文只是针对于某个问题提出的见解与论述,未必能辐射到相关问题的方方面面,所以本文处理问题的方法仅仅为您提供一些参考。更多问题请查阅学习中国网其他栏目哦. -----------------------------------------------------------------------------------------------------------------------------------------------
两个Label,组成控件数组并分别以与自已Index 值相同的PictureBox为父控件(只需把Label绘在或粘贴在相应的PictureBox上即可)属性:
AutoSize:True
Alignment:Center
BackStyle:Transparent
Label(1): Caption:″当前音量0″
Enabled:False
Label(0): Caption:″0%″
一个Timer:属性:Interval:50
三、实例
一个自动的进度条和由用户控制的进度条。
Option Explicit
′如果有多个进度条且表示值的范围不同
′则可设立一组范围值,最好能通过INDEX
′值同自已的进度条建立对应关系,以方便处理
Const MaxValue = 100
Const MinValue = 0
Dim Gene As Single
Dim ProValue(1) As Single
′生成比例因子,必须首先执行
Sub InitData()
Gene = Picture1(0).ScaleWidth /
(MaxValue - MinValue)
End Sub
′根据当前进度值设置进度条,INDEX指出是哪个进度条的值
Sub SetProBar(value As Single, Index As Integer)
Dim X As Single
Dim BkColor As Long
ProValue(Index) = value
′对当前进度值超出范围的处理
If ProValue(Index) > MaxValue Then
ProValue(Index) = MaxValue
Else
If ProValue(Index) < MinValue Then
ProValue(Index) = MinValue
End If
End If
′在存在多个进度条时分别设置各进度条的不同文本
Select Case Index
Case 1
Label1(Index).Caption = ProValue(Index) & ″%″
Case 0
Label1(Index).Caption = ″当前音量″ & ProValue(Index)
End Select
′计算出当前进度值所对应的进度条位置
X = (ProValue(Index) - MinValue) * Gene
With Picture1(Index).Picture = Image1.Picture
′把当前进度值所对应的进度条位置之后的图片用白色盖住
′它是此法实现思路的核心
Select Case Index
Case 1
bkcolor = vbWhite
Case 0
bkcolor = vbMenuBar
End Select
Picture1(Index).Line (X, 0)-(.ScaleWidth, _ .ScaleHeight), bkcolor, BF
End With
End Sub
′首先初始化比例因子
Private Sub Form_Load()
InitData
End Sub
′在用户操作INDEX为0的进度条时的响应
Private Sub picture1_MouseMove(Index As Integer, _
Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 And Index = 0 Then
Picture1_MouseDown Index, Button, Shift, X, Y
End If
End Sub
′根据当前鼠标坐标的X值(进度条若为纵向则使用Y值)
′计算出所对应的当前进度值,然后设置进度条
Private Sub Picture1_MouseDown(Index As Integer, _
Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 And Index = 0 Then
ProValue(Index) = Int(X / Gene + MinValue + 1)
SetProBar ProValue(Index), Index
End If
End Sub
′在演示中以定时器定时设置进度
′实际使用时当然是按事件完成的
′百分比来设置进度
Private Sub Timer1_Timer()
Static curval As Single
SetProBar curval, 1
curval = (curval + 1) Mod MaxValue
If curval = 0 Then
curval = MinValue
End If
End Sub
(河南 李捷)
本文章更多内容:<<上一页 - 1 - 2收藏到:[收藏夹] [百度搜藏] [新浪ViVi] [POCO网摘] [ 和讯网摘] [好哦网摘] [Google书签] [Yahoo书签] [搜狐网摘] [365Key网摘] [天极网摘] [我摘] [博采网摘] [igooi网摘] |