【正确答案】【操作步骤】 步骤1:打开本题工程文件。
步骤2:打开代码编辑窗口,去掉程序中的注释符,将问号改为正确的内容。
参考答案(字体加粗部分是需考生填入的内容)
Dim stepy As Integer '纵向移动增量
Dim stepx As Integer '横向移动增量
Const LEFT_BUTTON=1
Private Sub Form_MouseDown(Button As Integer,Shift As Integer,x As Single,y As Single)
Dim x0 As Integer,y0 As Integer,a As Single,radius As_Integer
radius=Shape1.Width/2 '圆的半径
If Button=LEFT_BUTTON Then
'单击鼠标左键移动
x0=Shape1.Left+radius '圆心的x坐标
y0=Shape1.Top+radius '圆心的y坐标
If x=x0 Then '垂直移动
stepy=Sgn(y-y0)*50
stepx=
0 Else '倾斜移动
a=(y-y0)/(x-x0) '斜率
stepx=Sgn(x-x0)*50
stepy=a*stepx
'通过stepx确定stepy的值
If Abs(stepy) >Abs (stepx)Then
stepy=Sgn(y-y0)*50
stepx=stepy/a
End If
End If
Timer1.Enabled=True '单击鼠标左键则触发Timer事件
Else
Timer1.Enabled=False '单击鼠标右键则停止Timer事件
End If
End Sub
Private Sub Timer1_Timer()
Shape1.Move Shape1.Left+stepx,Shape1.Top+stepy '移动shape1
End Sub
步骤3:调试并运行程序,关闭程序后按题目要求存盘。
【易错提示】语句比较复杂,要耐心地读懂程序,然后再做就很简单了。