国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

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

2024-07-21 02:20:57
字體:
來源:轉載
供稿:網友
運行效果:



設計方法:

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.運行看看效果吧。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 乌海市| 光山县| 景泰县| 宿州市| 鹰潭市| 文昌市| 东城区| 马山县| 博罗县| 潜江市| 白银市| 宁陕县| 博湖县| 准格尔旗| 成武县| 海门市| 江都市| 环江| 北流市| 桂林市| 哈尔滨市| 深水埗区| 大庆市| 佛山市| 连平县| 陕西省| 婺源县| 加查县| 都匀市| 华蓥市| 五华县| 济宁市| 喀喇沁旗| 五家渠市| 兴义市| 棋牌| 银川市| 柏乡县| 杭锦后旗| 新乐市| 昔阳县|