吧Timer2_Timer过程里的曲线绘图的代码修改如下:
For i = 0 To 绘图大小 - 1
'If py(k + i) > 0 Then '因为是从最左边开始绘图,所以要先判断一下数据是否有效
Picture2.Line (i * 20, 100 - py(k + i - 1))-(i * 20 + 20, 100 - py(k + i)), QBColor(1)
'End If
Next i
Private Sub Timer2_Timer() Dim i As Long Dim k As Long Dim s1 As String k = HScroll1.Value '绘图在 Picture2 进行,Picture2是不显示的。 Picture2.Cls Picture2.Line (0, 0)-(0, 210), QBColor(0) 'Y轴 Picture2.Line (0, 0)-(绘图大小 * 40 + 20, 0), QBColor(0) 'X轴 '每个点的竖线,以及显示标注 For i = 1 To 绘图大小 s1 = CStr(i + k - 1) Picture2.CurrentX = i * 40 - Picture2.TextWidth(s1) / 2 Picture2.CurrentY = 0 Picture2.Print s1 Picture2.Line (i * 40, 0)-(i * 40, 200), QBColor(2) Next i '每条刻度线,以及显示标注 For i = 1 To 10 s1 = CStr(i * 20 + 100) Picture2.Line (0, i * 20)-(绘图大小 * 40, i * 20), QBColor(2) Picture2.CurrentX = -Picture2.TextWidth(s1) Picture2.CurrentY = i * 20 - Picture2.TextHeight(s1) / 2 Picture2.Print s1 Next i 'Picture2.PSet (0, py(k - 1)), QBColor(2) For i = 0 To 绘图大小 - 1 If py(k + i) > 0 Then '因为是从最左边开始绘图,所以要先判断一下数据是否有效 Picture2.Line (i * 40, py(k + i - 1) - 100)-(i * 40 + 40, py(k + i) - 100), QBColor(1) End If Next i '把图像复制到 picture1中时行显示 Picture1.PaintPicture Picture2.Image, 0, 0 End Sub
Picture2.Cls Picture2.Line (0, 0)-(0, 210), QBColor(0) Picture2.Line (0, 90)-(1250, 90), QBColor(0) For i = 0 To 6 s1 = CStr(i * 50 - 150) Picture2.CurrentX = -Picture2.TextWidth(s1) Picture2.CurrentY = (i * 50 - Picture2.TextHeight(s1) / 2) / 1.5 Picture2.Print s1 Next i Picture2.PSet (0, py(k - 1)), QBColor(2) For i = 0 To 绘图大小 - 1 'If py(k + i) > 0 Then '因为是从最左边开始绘图,所以要先判断一下数据是否有效 Picture2.Line ((i * 40) / 2, (py(k + i - 1)) / 2)-((i * 40 + 40) / 2, (py(k + i)) / 2), QBColor(1) 'End If Next i Picture1.PaintPicture Picture2.Image, 0, 0
[此贴子已经被作者于2016-12-18 11:43编辑过]
Const X间隔 = 40 Const Y间隔 = 50 '加一个常量,防止新手搞错
Picture2.Scale (-50, 210)-(绘图大小 * X轴间隔 + X轴间隔/2, -220) '设置绘图区域坐标
Private Sub Timer2_Timer() Dim i As Long Dim k As Long Dim s1 As String k = HScroll1.Value '绘图在 Picture2 进行,Picture2是不显示的。 Picture2.Cls Picture2.Line (0, -210)-(0, 210), QBColor(0) 'Y轴 Picture2.Line (0, 0)-(绘图大小 * 40 + 20, 0), QBColor(0) 'X轴 '每个点的竖线,以及显示标注 For i = 1 To 绘图大小 s1 = CStr(i + k - 1) Picture2.CurrentX = i * X间隔 - Picture2.TextWidth(s1) / 2 Picture2.CurrentY = -200 Picture2.Print s1 Picture2.Line (i * X间隔, -200)-(i * X间隔, 200), QBColor(2) Next i '每条刻度线,以及显示标注 For i = -4 To 4 s1 = CStr(i * Y间隔) If i <> 0 Then 'X轴不重画 Picture2.Line (0, i * Y间隔)-(绘图大小 * X间隔, i * Y间隔), QBColor(2) End If Picture2.CurrentX = -Picture2.TextWidth(s1) Picture2.CurrentY = i * Y间隔 - Picture2.TextHeight(s1) / 2 Picture2.Print s1 Next i 'Picture2.PSet (0, py(k - 1)), QBColor(2) For i = 0 To 绘图大小 - 1 ' If py(k + i) > 0 Then '因为是从最左边开始绘图,所以要先判断一下数据是否有效 Picture2.Line (i * X间隔, py(k + i - 1))-(i * X间隔 + X间隔, py(k + i)), QBColor(1) ' End If Next i '把图像复制到 picture1中时行显示 Picture1.PaintPicture Picture2.Image, 0, 0 End Sub