首页 > 编程 > .NET > 正文

vb.net 中实现画图,以及TrackBar和画出图形的绑定

2024-07-10 13:05:21
字体:
来源:转载
供稿:网友
 

项目中要用图形来显示一个阀门的开度,以及控制阀的开度。本来是要用什么公司买的控件中的饼图之类的实现,不过我觉得也是麻烦,就想,还是自己画吧。

首先添加一个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, 5), i, m_start + 20, i, 120)
            next

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

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



发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表