'程序有点错误,时间不够,你先参考下,左划放大,右划还原 Private mX As Single, mY As Single Private Sub DrawScale(x1, y1, x2, y2) Picture1.Cls xx = (x2 - x1) / 20: yy = (y2 - y1) / 20 If xx < 5 Then xx = 5: If yy < 5 Then yy = 5 Picture1.Scale (x1 - xx, y1 - yy)-(x2 + xx, y2 + yy) Picture1.Line (x1, y1)-(x1, y2) Picture1.Line (x1, y2)-(x2, y2) Picture1.CurrentY = y1 For X = x1 To x2 Step (x2 - x1) / 10 Picture1.CurrentX = X Picture1.Print X Next Picture1.CurrentX = x2 For Y = y1 To y2 Step (y2 - y1) / 10 Picture1.CurrentY = Y Picture1.Print Y Next End Sub Private Sub Form_Load() DrawScale 0, 10, 100, 0 DrawFunc 0, 100 End SubPrivate Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) mX = X: mY = Y End SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Me.Caption = CInt(X) & "," & CInt(Y) End Sub Private Sub DrawFunc(x1, x2) Picture1.PSet (x1, Sin(x1)) For X = x1 To x2 Step (x2 - x1) / 500 Picture1.Line -(X, Sin(X)), vbGreen Next End SubPrivate Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) If X > mX Then DrawScale mX, mY, X, Y DrawFunc mX, X Else DrawScale 0, 10, 100, 0 DrawFunc 0, 100 End IfEnd Sub
然后每次点击,从picture里面获得的位置左右上下定好框,把需要的部分保存成临时文件用来缩放
这个效率肯定比API差很多。
PictureBox.Scale设定坐标
PictureBox.Line绘制直线
PictureBox.PSet绘制点(注:这个方法VB没有提供智能提示,语法是Picture1.PSet(x1,y1)
首先绘制出坐标系,然后绘制两个假定的函数f(x),g(x),可以增加一个比较两个函数绝对值的函数,或者借鉴最小二乘法,希望能帮上你。
Private mX As Single, mY As Single
Private Sub DrawScale(x1, y1, x2, y2)
Picture1.Cls
xx = (x2 - x1) / 20: yy = (y2 - y1) / 20
If xx < 5 Then xx = 5: If yy < 5 Then yy = 5
Picture1.Scale (x1 - xx, y1 - yy)-(x2 + xx, y2 + yy)
Picture1.Line (x1, y1)-(x1, y2)
Picture1.Line (x1, y2)-(x2, y2)
Picture1.CurrentY = y1
For X = x1 To x2 Step (x2 - x1) / 10
Picture1.CurrentX = X
Picture1.Print X
Next
Picture1.CurrentX = x2
For Y = y1 To y2 Step (y2 - y1) / 10
Picture1.CurrentY = Y
Picture1.Print Y
Next
End Sub
Private Sub Form_Load()
DrawScale 0, 10, 100, 0
DrawFunc 0, 100
End SubPrivate Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
mX = X: mY = Y
End SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.Caption = CInt(X) & "," & CInt(Y)
End Sub
Private Sub DrawFunc(x1, x2)
Picture1.PSet (x1, Sin(x1))
For X = x1 To x2 Step (x2 - x1) / 500
Picture1.Line -(X, Sin(X)), vbGreen
Next
End SubPrivate Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If X > mX Then
DrawScale mX, mY, X, Y
DrawFunc mX, X
Else
DrawScale 0, 10, 100, 0
DrawFunc 0, 100
End IfEnd Sub