vb.netgraph的简单介绍
vb.net 画直线问题
'把“Dim graph As Graphics = Me.CreateGraphics”挪到“Button1_Click”事件内,调试过成功!
10年积累的做网站、网站设计经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先建设网站后付款的网站建设流程,更有历城免费网站建设让你可以放心的选择与我们合作。
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim graph As Graphics = Me.CreateGraphics
Dim pen2 As Pen = New Pen(Color.Green, 3)
graph.DrawLine(pen2, 400, 400, 500, 200)
End Sub
End Class
VB中,将从下位机读取的数据,用控件的方式画出以时间为横轴的曲线
1.用picturebox 控件可以实现
2.可以使用Scale方法移动坐标原始位置和改变坐标轴方向,以下该方法:
Scale(x1,y1)-(x2,y2)
X1和y1为对象左上角的新坐标位置;
X2和y2为对象右下角的新坐标位置;
现在让我们看看一些范例。这一方法将使原点处于左上角,但将坐标系统单位改变为窗体大小的1/100:
Picture1.Scale(0,0)-(100,100)
以下调用将移动原点到窗体的左下角,并旋转Y轴:
Picture1.Scale(0,100)-(100, 0)
以下调用将移动原点到窗体的正中心,并旋转Y轴,然后将坐标单位转换为窗体大小的1/5000:
Picture1.Scale(-2500,2500)-(2500,2500)
用Picture1.Line (x1,y1)-(x2,y2)
如果不指定(x1,y1)则line方法默认为上次line方法的(x2,y2)为当前line方法(x1,y1)
For i = 1 To 100
j = i + 10
Me.Picture1.Line -(i, j), vbRed '可以指定画线的颜色
Next
3.如果画到最右边的时候,可以清掉picturebox 的内容,从头再画。
给段代码,供参考:
Private Sub Form_Load()
Dim i, j As Integer
Me.Picture1.Scale (0, Me.Picture1.Height)-(Me.Picture1.Width, 0)
Me.Picture1.AutoRedraw = True
Me.Picture1.Line (0, 0)-(0, 0), vbRed
For i = 1 To 1000
j = i + 10
Me.Picture1.Line -(i, j), vbRed
Next
End Sub
我这样画过曲线,大概思路就是这样吧,希望能帮到你
vb.net 画线再画保留以前画得
可以把所有画的线都保存在一个列表中,画的时候全部画出即可。如下:
Public Class Form1
Class Line '直线类
Public Point1, Point2 As Point '成员,直线的两个端点
Sub New(p1 As Point, p2 As Point) '构造方法
Point1 = p1
Point2 = p2
End Sub
Public Sub Draw(g As Graphics) '绘制方法
g.DrawLine(Pens.Black, Point1, Point2)
End Sub
End Class
Private Lines As New List(Of Line) '列表用于保存所有画下的直线
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
BackColor = Color.White
DoubleBuffered = True '开启双缓冲可有效避免闪烁
End Sub
Private Sub Form1_MouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown
Lines.Add(New Line(e.Location, e.Location)) '在直线列表中添加直线
End Sub
Private Sub Form1_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
If e.Button Windows.Forms.MouseButtons.Left Then Return '左键未按下
'鼠标拖动时改变列表最后一条直线(也即当前直线的第二个端点)
Lines(Lines.Count - 1).Point2 = e.Location
Refresh() '刷新窗体
End Sub
'在Form的Paint事件中绘制所有直线,每次Form1重绘时都会触发Paint事件
'PS: 也可以通过重写OnPaint方法来达到类似的效果
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias '开启抗锯齿
For Each l In Lines '遍历所有直线
l.Draw(e.Graphics) '调用绘制方法,传入的参数可以理解为画布
Next
End Sub
End Class
运行效果:
vb.net中,我用picturebox控件画曲线。使用picturebox.CreateGraphics()画线,请教保存问题??
首先你要建一个 Bitmap
再将picture控件的image属性与之相关联
再到 picture的image上画线
保存image到文件
/////////////////////////////////
Dim mybitmap As Bitmap
mybitmap = New Bitmap(300, 150)
PictureBox0.Image = mybitmap
Dim Graph As Graphics
Graph =Graphics.FromImage(PictureBox0.image)
Graph .drawline(Pens.Blue,0,0,111,111)
picturebox0.image.save("c:\aaa.jpg")
/////////////////////////////////////
存成的文件绝对有你画的线..我一直在用这种方法
网站栏目:vb.netgraph的简单介绍
文章源于:http://scyanting.com/article/dsgdoei.html