自己编写vb进度条控件

在这里插入图片描述

主程序代码:

Option Explicit

Dim i As Double

Private Sub Command1_Click()
i = 0
Timer1.Interval = 50
Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
i = i + 0.05
ProcessBar1.Percent = i
If i > 1 Then Timer1.Enabled = False
End Sub

在这里插入图片描述

控件代码:

Option Explicit

Public Enum FigureStyle
eOnlyValueInt
eOnlyValueDouble
ePercentInt
ePercentDouble
End Enum

Private dblMyPercent As Double
Private lngMyValue As Long
Private isShowMsg As Boolean
Private strMsg As String
Private intMsgStyle As FigureStyle

Private Max As Long, Min As Long

Private Sub UserControl_Initialize()
Min = 0
Max = 100
’ lngMyValue = 30
dblMyPercent = lngMyValue / (Max - Min)
lblValue.Caption = Int(dblMyPercent * 100) & “/100”
UserControl.Height = lblBase.Height
intMsgStyle = ePercentInt

Call setLabelSize

End Sub

Private Sub UserControl_Resize()
Call setLabelSize
End Sub

Private Sub setLabelSize()
lblBase.Move 0, 0, UserControl.ScaleWidth, UserControl.ScaleHeight
lblTop.Move lblBase.Left, lblBase.Top, dblMyPercent * lblBase.Width, lblBase.Height
lblValue.Move lblBase.Left, (lblBase.Height - lblValue.Height) / 2 + 20, lblBase.Width
End Sub
'set the value
Public Property Let Value(ByVal Value As Long)
If Value < Min Then
lngMyValue = Min
ElseIf Value > Max Then
lngMyValue = Max
Else
lngMyValue = Value
End If

dblMyPercent = lngMyValue / (Max - Min)
lblTop.Width = dblMyPercent * lblBase.Width
Select Case intMsgStyle
    Case eOnlyValueInt: strMsg = Int(dblMyPercent * 100)
    Case eOnlyValueDouble: strMsg = CStr(dblMyPercent * 100)
    Case ePercentInt: strMsg = Int(dblMyPercent * 100) & "/100"
    Case ePercentDouble: strMsg = CStr(dblMyPercent * 100) & "/100"
End Select
lblValue.Caption = strMsg

End Property

Public Property Get Value() As Long
Value = lngMyValue
End Property
'set the percent
Public Property Let Percent(ByVal Percent As Double)
If Percent < 0 Then
dblMyPercent = 0
ElseIf Percent > 1 Then
dblMyPercent = 1
Else
dblMyPercent = Percent
End If

lngMyValue = dblMyPercent * (Max - Min)
lblTop.Width = dblMyPercent * lblBase.Width
Select Case intMsgStyle
    Case eOnlyValueInt: strMsg = Int(dblMyPercent * 100)
    Case eOnlyValueDouble: strMsg = CStr(dblMyPercent * 100)
    Case ePercentInt: strMsg = Int(dblMyPercent * 100) & "/100"
    Case ePercentDouble: strMsg = CStr(dblMyPercent * 100) & "/100"
End Select
lblValue.Caption = strMsg

End Property

Public Property Get Percent() As Double
Percent = dblMyPercent
End Property
'is show msg
Public Property Let ShowMsg(ByVal ShowMsg As Boolean)
isShowMsg = ShowMsg
lblValue.Visible = isShowMsg
End Property

Public Property Get ShowMsg() As Boolean
ShowMsg = isShowMsg
End Property
'msg style
Public Property Let MsgStyle(ByVal MsgStyle As FigureStyle)
intMsgStyle = MsgStyle
Select Case intMsgStyle
Case eOnlyValueInt: strMsg = Int(dblMyPercent * 100)
Case eOnlyValueDouble: strMsg = CStr(dblMyPercent * 100)
Case ePercentInt: strMsg = Int(dblMyPercent * 100) & “/100”
Case ePercentDouble: strMsg = CStr(dblMyPercent * 100) & “/100”
End Select
lblValue.Caption = strMsg
End Property

Public Property Get MsgStyle() As FigureStyle
MsgStyle = intMsgStyle
End Property

以下为运行状态:

在这里插入图片描述
在这里插入图片描述

整个工程下载:https://github.com/sysdzw/vbprocessbar

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值