人人做人人澡人人爽欧美,国产主播一区二区,久久久精品五月天,羞羞视频在线观看免费

當前位置:蘿卜系統下載站 > 技術開發教程 > 詳細頁面

VB編寫一個能顯示百分比的自定義進度條控件

VB編寫一個能顯示百分比的自定義進度條控件

更新時間:2022-10-11 文章作者:未知 信息來源:網絡 閱讀次數:

運行效果:



設計方法:

1.在UserControl中添加一個Label控件Label1,將它設為平面,用來做外框。添加兩個PictureBox控件PictureBox1做為進度指示,PictureBox2控件做為控件背景。



2.加入以下代碼

Option Explicit

'定義私有變量用于存儲屬性值
Private mvarMax As Long
Private mvarMin As Long
Private mvarValue As Long

Private Rate As String

Private Sub UserControl_Initialize()
'初始化
Picture2.BackColor = vbBlue
End Sub

Public Property Get BackColor() As OLE_COLOR
'讀取BackColor屬性
BackColor = Picture1.BackColor
End Property

Public Property Let BackColor(ByVal vNewValue As OLE_COLOR)
'設置BackColor屬性
Picture1.BackColor = vNewValue
End Property

Private Sub UserControl_InitProperties()
'初始化屬性
Max = 100
Min = 0
Value = 0
End Sub

Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
'讀取從屬性窗體中設置的屬性值
mvarMax = PropBag.ReadProperty("Max", 100)
mvarMin = PropBag.ReadProperty("Min", 0)
'Value屬性值這里未提供,主要是模仿VB自帶的進度條控件
'mvarValue = PropBag.ReadProperty("Value", 0)
End Sub

Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
'保存從屬性窗體中設置的屬性值
PropBag.WriteProperty "Max", mvarMax, 100
PropBag.WriteProperty "Min", mvarMin, 0
'PropBag.WriteProperty "Value", mvarValue, 0
End Sub

Private Sub UserControl_Resize()
'Resize事件
Label1.Move 0, 0, UserControl.Width / Screen.TwipsPerPixelX, UserControl.Height / Screen.TwipsPerPixelY
Picture1.Move 1, 1, UserControl.Width / Screen.TwipsPerPixelX - 2, UserControl.Height / Screen.TwipsPerPixelY - 2
Picture2.Move 1, 1, 1, UserControl.Height / Screen.TwipsPerPixelY - 2
End Sub

Public Property Get Max() As Long
'讀取Max屬性
Max = mvarMax
End Property

Public Property Let Max(ByVal vNewValue As Long)
'設置Max屬性
mvarMax = vNewValue
If vNewValue < Min Then Err.Raise "1001", , "Max必須大于Min"
End Property

Public Property Get Min() As Long
'讀取Min屬性
Min = mvarMin
End Property

Public Property Let Min(ByVal vNewValue As Long)
'設置Min屬性
If vNewValue > Max Then Err.Raise "1000", , "Min必須小于Max"
mvarMin = vNewValue
End Property

Public Property Get Value() As Long
'讀取Value屬性
Value = mvarValue
End Property

Public Property Let Value(ByVal vNewValue As Long)
'設置Value屬性
'原理就是在兩個PictureBox中以不同顏色打印百分比進度
Dim DX As Long, DY As Long

If vNewValue > Max Then Err.Raise "1002", , "Value不能大于Max"
mvarValue = vNewValue

Picture2.Width = Value / (Max - Min) * (UserControl.Width / Screen.TwipsPerPixelX - 2)
Rate = Int(Value / (Max - Min) * 100) & "%"
DX = (Picture1.Width - Picture1.TextWidth(Rate)) / 2
DY = (Picture1.Height - Picture1.TextHeight(Rate)) / 2
Picture1.ForeColor = vbBlack
Picture2.ForeColor = vbWhite
If DX < Picture2.Width Then
Picture2.Cls
Picture2.CurrentX = DX
Picture2.CurrentY = DY
Picture2.Print Rate
Else
Picture1.Cls
Picture1.CurrentX = DX
Picture1.CurrentY = DY
Picture1.Print Rate
End If
End Property

3.新建另一個測試工程,加入一個自己的進度條控件和一個系統的進度條控件,加入以下代碼:

Option Explicit

Private Sub Command1_Click()
Unload Me
End Sub

Private Sub Timer1_Timer()
myProgressBar1.Value = myProgressBar1.Value + 2
ProgressBar1.Value = ProgressBar1.Value + 2
If myProgressBar1.Value = myProgressBar1.Max Then Timer1.Enabled = False
End Sub


OK.運行看看效果吧。

溫馨提示:喜歡本站的話,請收藏一下本站!

本類教程下載

系統下載排行

網站地圖xml | 網站地圖html
主站蜘蛛池模板: 五常市| 北京市| 历史| 璧山县| 泸西县| 永登县| 广西| 旬阳县| 长武县| 海盐县| 梁平县| 金华市| 梨树县| 军事| 于田县| 伊宁市| 山丹县| 富宁县| 威信县| 乳山市| 新蔡县| 南阳市| 砚山县| 桐梓县| 全南县| 新兴县| 水富县| 黄梅县| 舒城县| 济源市| 施甸县| 思南县| 哈巴河县| 焦作市| 汝南县| 兴业县| 丘北县| 始兴县| 称多县| 青海省| 丰台区|