VB中画图的问题

现在有两列数据
0 -531
60 -532
120 -532
180 -526
240 -530
300 -532
360 -532
420 -532
480 -532
540 -533
600 -533
660 -535
720 -535
780 -535
840 -535
900 -535
960 -527
1020 -534
1080 -535
1140 -535
1200 -535
1260 -535
1320 -535
1380 -535
1440 -535
1500 -535
1560 -535
1620 -535
1680 23 -535
1740 -535
1800 -535
1860 -535
1920 -535
1980 -535
2040 -535
2100 -535
2160 -535
2220 -533
2280 -534
2340 -535
2400 -535
2460 -535
2520 -535
2580 -535
2640 -535
2700 -535
2760 -535
第一列是时间,第二列是电位,数据不只这些,后面还有很多,就不全部给出了,反正时间最后达到了70000 电位在-600到-480之间变化,现在需要一一描点画出图形,请给为高手给出详细代码,感激不尽!

1、将你的这些数据复制到a.txt中,并将其放到d盘根目录。
0 -531
60 -532
120 -532
180 -526
240 -530
300 -532
360 -532
420 -532
480 -532
540 -533
600 -533
660 -535
720 -535
780 -535
840 -535
900 -535
960 -527
1020 -534
1080 -535
1140 -535
1200 -535
1260 -535
1320 -535
1380 -535
1440 -535
1500 -535
1560 -535
1620 -535
1680 -535
1740 -535
1800 -535
1860 -535
1920 -535
1980 -535
2040 -535
2100 -535
2160 -535
2220 -533
2280 -534
2340 -535
2400 -535
2460 -535
2520 -535
2580 -535
2640 -535
2700 -535
2760 -535
2.新建一个标准exe工程,在窗体上画出一个按钮command1,一个标签label1,并将其indix属性设为0
3、将下列代码复制到代码窗口

Private Sub Command1_Click()
Open "D:\a.txt" For Input As #1
'Input #1, x, y
Form1.Line (2, 2)-(2, 2)
Do While Not EOF(1)
Input #1, x, y
Form1.Line -(x / 30 + 2, -(y + 519) * 2), &HFF&
Loop
Close #1
End Sub

Private Sub Form_Load()
Me.AutoRedraw = True
Show
Me.ScaleHeight = 44 '将窗体的高设定为44份
Me.ScaleWidth = 50 '将窗体的宽设定为50份
'Me.Line.BorderColor = &H0&
Me.Line (2, 2)-(2, 42), &H0& '画出纵坐标
Me.Line (2, 2)-(48, 2), &H0& '画出横坐标
Me.Line (48, 2)-(47.5, 1.5), &H0& '画出横坐标上的箭头
Me.Line (48, 2)-(47.5, 2.5), &H0&
Me.Line (2, 42)-(1.75, 41), &H0& '画出纵坐标上的箭头
Me.Line (2, 42)-(2.25, 41), &H0&
Label1(0).Width = 20 '写出坐标原点
Label1(0).Height = 20
Label1(0).AutoSize = ture
Label1(0).BackStyle = 0
Label1(0).FontItalic = True
Label1(0).FontBold = True
Label1(0).FontSize = 10
Label1(0).ForeColor = &HFF&
Label1(0).Caption = 0
Label1(0).Left = 1.2
Label1(0).Top = 0.5
Label1(0).Visible = True
For i = 1 To 25
Load Label1(i) '用数组的方法动态添加控件(横坐标示数)
Label1(i).Width = 40
Label1(i).Height = 20
Label1(i).AutoSize = ture
Label1(i).BackStyle = 0
Label1(i).FontItalic = True
Label1(i).FontBold = True
Label1(i).FontSize = 10
Label1(i).ForeColor = &HFF&
Label1(i).Caption = i * 60
Label1(i).Left = 1.5 + i * 2
Label1(i).Top = 0.2
Label1(i).Visible = True
'动态添加控件(横坐标上的间隔线)
Set newobj = Me.Controls.Add("vb.line", "Line" & i)
With newobj
.BorderStyle = 3
.X1 = 2 * i + 2
.X2 = 2 * i + 2
.Y1 = 2
.Y2 = 42
End With
newobj.Visible = True
Next i
For i = 41 To 60
Load Label1(i)
Label1(i).Width = 40
Label1(i).Height = 20
Label1(i).AutoSize = ture
Label1(i).BackStyle = 0
Label1(i).FontItalic = True
Label1(i).FontBold = True
Label1(i).FontSize = 10
Label1(i).ForeColor = &HFF&
Label1(i).Caption = (i + 480) * (-1)
Label1(i).Left = 0.2
Label1(i).Top = 1.4 + 2 * (i - 40)
Label1(i).Visible = True
Set newobj = Me.Controls.Add("vb.line", "Line" & i)
With newobj
.X1 = 2
.X2 = 48
.Y1 = 2 * (i - 40)
.Y2 = 2 * (i - 40)
.BorderStyle = 3
End With
newobj.Visible = True
Next i
End Sub

4、运行
温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-03-06
楼主只要这样改动就可以相切了。
Picture1.Circle
(0,
-2),
2
/
(Picture1.Width
/
Picture1.Height)
楼主的问题很有价值,我在回答中也发现了这个有趣的问题。
经过分析,我发现这与图片框的长宽比例有关。还有一点就是不管scale和图片框的
比例如何设置,画的圆从外观看来,总是圆的。而且这里的半径,是否是以x方向为准,
如果图片框的y方向很窄,那么圆有可能超出y的范围。
最终经过测试,我发现了上面的半径系数可以让你的圆永远相切。
请采纳答案,支持我一下。
第2个回答  2019-08-13
建一个水平的Line1。垂直的类似。我以水平的为例。
代码如下。
===============
Dim
f
As
Boolean
Private
Sub
Form_MouseDown(Button
As
Integer,
Shift
As
Integer,
X
As
Single,
Y
As
Single)
f
=
X
>
Line1.X1
And
X
<
Line1.X2
And
Y
>
Line1.Y1
-
10
And
Y
<
Line1.Y1
+
10
End
Sub
Private
Sub
Form_MouseMove(Button
As
Integer,
Shift
As
Integer,
X
As
Single,
Y
As
Single)
MousePointer
=
IIf(X
>
Line1.X1
And
X
<
Line1.X2
And
Y
=
Line1.Y1,
vbSizeNS,
vbDefault)
If
f
=
True
Then
Line1.Y1
=
Y
Line1.Y2
=
Y
End
If
End
Sub
Private
Sub
Form_MouseUp(Button
As
Integer,
Shift
As
Integer,
X
As
Single,
Y
As
Single)
f
=
False
End
Sub
第3个回答  2019-02-03
设置
Picture1.AutoRedraw
=
True
即可
第4个回答  2020-01-07
Dim
j
As
Integer
Private
Static
Sub
Command1_Click()
DrawWidth
=
20
j
=
j
+
400
Line
(500,
j)-Step(1000,
0)
End
Sub
Private
Sub
Form_Load()
j
=
1001
End
Sub
第5个回答  2019-09-05
一、点(x,y)默认在picturebox的中间,可这样设置:
x=Picture1.ScaleWidth/2
y=Picture1.ScaleHeight/2
在此处画的点,即为图片中间点。
二、用Picture1.Cls即可清除所画的内容,还原为一张白纸。
相似回答