新建From1(窗体),新建Command1(按钮CommandButton),Picture1(PictureBox)代码:
Const pi = 3.14159
Dim a
Private Sub Command1_Click() '注释:画抛物线
'首先清除picture1内的图形
Picture1.Cls
'注释:Scale方法设定用户坐标系,坐标原点在Picture1中心
Picture1.ScaleMode = 0
Picture1.ScaleMode = 3
Picture1.Scale (-20, 20)-(20, -20)
'设置绘线宽度
Picture1.DrawWidth = 1
'绘坐标系的X轴及箭头线
Picture1.Line (-20, 0)-(20, 0), vbBlue
Picture1.Line (18, 1)-(20, 0), vbBlue
Picture1.Line -(18, -1), vbBlue
Picture1.ForeColor = vbBlue
Picture1.Print "X"
' 绘坐标系的Y轴及箭头线
Picture1.Line (0, 20)-(0, -20), vbBlue
Picture1.Line (1, 18)-(0, 20), vbBlue
Picture1.Line -(-1, 18), vbBlue
Picture1.Print "Y"
'指定位置显示原点O
Picture1.CurrentX = 1
Picture1.CurrentY = -1
Picture1.Print "O"
'重设绘线宽度
Picture1.DrawWidth = 2
'注释:用For循环绘点,使其按抛物线规律变化。步长值很小,使之形成动画效果
For a = -10 To 10 Step pi / 6000
Picture1.PSet (a, a ^ 2 / 5), vbRed
Next a
'指定位置显示描述文字
Picture1.CurrentX = pi / 2
Picture1.CurrentY = -7
Picture1.ForeColor = vbBlack
Picture1.Print "抛物线示意"
End Sub