项目中要用图形来显示一个阀门的开度,以及控制阀的开度。本来是要用什么公司买的控件中的饼图之类的实现,不过我觉得也是麻烦,就想,还是自己画吧。
成都创新互联公司 - 服务器托管,四川服务器租用,成都服务器租用,四川网通托管,绵阳服务器托管,德阳服务器托管,遂宁服务器托管,绵阳服务器托管,四川云主机,成都云主机,西南云主机,服务器托管,西南服务器托管,四川/成都大带宽,机柜大带宽,四川老牌IDC服务商
首先添加一个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
到此以及可以实现拉动条的时候,茄销图像尺蚂跟着变化,并显示百分比。
。net 其实还是很好绘制图形的
你可以看下 Graphics 类
Dim d As New Bitmap(Me.Width, Me.Height) ‘一个图片吧
Dim g As Graphics = Graphics.FromImage(d)’绘制 脊塌轮准备在这个图片是进行
然后 就是你绘制的东西了
线 就是 g.DrawLine()
圆 弧衫唤度 就用 g.DrawArc(Pens.Black, New Rectangle(0, 0, 400, 200), 0, 360)
复杂的就是 g.DrawBezier()
等 如果你用的是 VS的 编译 上面都有详细的参数说明
樱信 Dim d As New Bitmap(Me.Width, Me.Height)
Dim g As Graphics = Graphics.FromImage(d)
g.DrawArc(Pens.Black, New Rectangle(0, 0, 200, 200), 0, 360)
g.DrawLine(Pens.Red, New Point(0, 0), New Point(200, 200))
g.DrawLines(Pens.Green, New Point() {New Point(0, 0), New Point(50, 40), New Point(50, 80), New Point(90, 70), New Point(100, 400)})
g.DrawBezier(Pens.Yellow, New Point(0, 100), New Point(0, 0), New Point(200, 0), New Point(200, 200))
g.Dispose()
Me.BackgroundImage = d
分类: 电脑/网络 程序设计 其他编程语言枝渣改
问题描述:
VB6中的form1.circle (100,200),rgb(0,255,0)的语句如何在VB中使用啊?
急用啊!梁早!!!!!!!
解析:
VB与VB不同。
VB已经有专门绘图的类。
可以定义笔刷然后用Drawing类中的方法绘猛判制。
Private Sub DrawEllipse()
Dim myPen As New System.Drawing.Pen(System.Drawing.Color.Red)
Dim formGraphics as System.Drawing.Graphics
formGraphics = Me.CreateGraphics()
formGraphics.DrawEllipse(myPen, New Rectangle(0,0,200,300))
myPen.Dispose()
formGraphics.Dispose()
End Sub
Private Sub DrawRectangle()
Dim myPen As New System.Drawing.Pen(System.Drawing.Color.Red)
Dim formGraphics as System.Drawing.Graphics
formGraphics = Me.CreateGraphics()
formGraphics.DrawRectangle(myPen, New Rectangle(0,0,200,300))
myPen.Dispose()
formGraphics.Dispose()
End Sub