首先,启动VB6,新建标准EXE工程,添加一个PictureBox控件,两个CommandButton控件到窗体,其Caption属性值分别设为抛物线和结束。
双击Command1,打开代码编辑器窗口,相应事件的代码如下:
通用声明模块:
Const pi = 3.14159
Dim a
Private Sub Command2_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
Private Sub Command3_Click()
Unload Me
End Sub
以上程序代码在VB6.0,Windows 98中调试通过。
延伸阅读
文章来源于领测软件测试网 https://www.ltesting.net/