这是画点的:
创新互联成立于2013年,先为淮北等服务建站,淮北等地企业,进行企业商务咨询服务。为淮北企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
Private Sub Form_Click()
Dim X(7) As Integer, Y(7) As Integer, i%
Form1.Scale (-15, 15)-(15, -15)
Form1.Line (0, 0)-(15, 0)
Form1.Line (0, 15)-(0, 0)
For i = 0 To 12 'Step 1.2 'X轴坐标
Form1.Line (i, 0.1)-(i, 0)
CurrentX = i
CurrentY = -1
Form1.Print i
Next i
For i = 0 To 12 'Step 1.2 'Y轴坐标
Form1.Line (0, i)-(0.3, i)
CurrentX = -0.5
CurrentY = i
Form1.Print i
Next i
X(0) = 0: X(1) = 2: X(2) = 4: X(3) = 6: X(4) = 8: X(5) = 10: X(6) = 12: X(7) = 14
Y(0) = 0: Y(1) = 1: Y(2) = 3: Y(3) = 4: Y(4) = 3: Y(5) = 2: Y(6) = 1: Y(7) = 0
For i = 0 To 7
Form1.PSet (X(i), Y(i)), vbRed
Next i
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
在VB中绘制实时曲线是比较难的,一般要应用第三方控件或是Windows
API函数来完成,但是如果你对实时曲线的要求不是很高,只要能表示出当前的一般情况的话,我们可以直接应用VB提供给我们的空间来完成.
原则上讲,直接在Form里绘制曲线都是可以的,MSDN上面很多例程就是直接在Form里面绘制图形的,Form作为绘制图形的容器,不过一般应用中Form中不可避免的会有很多其他控件,所以我们选择PictureBox作为绘制曲线的容器.
实时曲线的绘制一般借助于Timer控件来完成,使用Timer控件,定期将串口或是其他仪器中监测到的数据送往PictureBox1,而曲线的绘制一般画成折线图,采用PictureBox1的Line方法绘制.具体实现如下:
1.选择需要显示的窗体Picture1,加入图片框Picture1,根据实际需要设置图片的大小并移到合适的位置,并在图片的外面画好量程----时间坐标系;然后加上Timer控件以及两个CommandButton,界面就基本设置好了.
2.建立坐标系,根据Picture1的大小和高度设置画出坐标系的X轴和Y轴:
Picture1
.ScaleMode
=
1
‘以VB的基本单位作为建立坐标轴以及绘制图形的单位;
Picture1.Refresh
Picture1.CurrentX
=
Picture1.ScaleLeft
+100
Picture1.CurrentY
=
Picture1.ScaleTop
Picture1.Print
Picture1.ScaleHeight
-
100
Picture1.Line(Picture1.ScaleLeft+100,Picture1.ScaleTop+100)-(Picture1.ScaleLeft+100,
Picture1.ScaleHeight
-
100)
Picture1.CurrentX
=
Picture1.ScaleLeft
+100
Picture1.CurrentY
=
Picture1.ScaleHeight
Picture1.Print
“(0,0)”
Picture1.Line
(Picture1.ScaleLeft
+
100,
Picture1.ScaleHeight
-
100)-(Picture1.ScaleWidth
-
100,
Picture1.ScaleHeight
-
100)
Picture1.CurrentX
=
Picture1.ScaleWidth
Picture1.CurrentY
=
Picture1.ScaleHeight
Picture1.Print
Picture1.ScaleWidth-100
Picture1.AutoRedraw
=
True
‘必要时,用存储在内存中的图象进行重绘
3.绘制曲线并保存,我们这里以正弦曲线作为绘制曲线的数据来源,具体应用是可以采用由串口或其他仪器采集得到的数据.首先我们绘制一条中线,然后在Timer控件的Time事件中绘制曲线:
Picture1.Line
(Picture1.ScaleLeft,
CInt(Picture1.ScaleHeight
/
2))-(Picture1.ScaleWidth,
CInt(Picture1.ScaleHeight
/
2))
‘绘制中线
Private
Sub
Timer1_Timer()
Dim
y1
As
Integer
y1
=
CInt(Sin((x
-
Picture1.Left)
/
20
/
180
*
pi)
*
Picture1.ScaleHeight
/
2)
y1
=
CInt((Picture1.ScaleHeight
+
1000)
/
2)
-
y1
Picture1.Line
(x,
y)-(x
+
20,
y1)
x
=
x
+
20
y
=
y1
If
x
=
Picture1.ScaleWidth
Then
SavePicture
Picture1.Image,
"c:\sin.bmp"
‘保存图画,