vb.net里使用trackbar控件控制图形

前端之家收集整理的这篇文章主要介绍了vb.net里使用trackbar控件控制图形前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

项目中要用图形来显示一个闸门的开度,以及控制闸的开度。首先添加一个trackbar,名字是“trackbar1”,一个label,名字是“l_a_shang”,一个groupBox,名字是“gb_right”,,然后添加拉动滚动条时的处理函数

上位机控制
dim m_start as integer
dim rcdraw as system.drawing.rectangle


private sub trackbar1_scroll(byval sender as object,byval e as system.eventargs) handles trackbar1.scroll
m_start = (100 - trackbar1.value)
me.l_a_shang.text = me.trackbar1.value.tostring
gb_right.invalidate() 重画gb_right
end sub

添加gb_right重画时的处理函数

private sub gb_right_paint(byval sender as object,byval e as system.windows.forms.painteventargs) handles gb_right.paint
rcdraw.x = trackbar1.location.x - 40
rcdraw.y = 20
rcdraw.height = 100
rcdraw.width = 20
e.graphics.drawrectangle(new pen(color.blue,5),rcdraw)
dim i = trackbar1.location.x - 40
for i = trackbar1.location.x - 40 to trackbar1.location.x - 20
e.graphics.drawline(new pen(color.blue,i,m_start + 20,120)
next

me.l_a_shang.text = me.trackbar1.value.tostring + "%"
end sub

到此以及可以实现拉动条的时候,图像跟着变化,并显示百分比。

原文链接:https://www.f2er.com/vb/262017.html

猜你在找的VB相关文章