项目中要用图形来显示一个闸门的开度,以及控制闸的开度。首先添加一个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
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