用vb绘制图形并使其运动

来源:互联网 发布:淘宝权女朋友是谁 编辑:程序博客网 时间:2024/05/21 05:18

用VB绘制图形并使其运动

绘制圆形并运动的程序代码

打开VB6.0程序,新建一个窗体。应用command画出一个按钮,将command的caption属性改为“开始运动”;插入一个timer,将其interval属性改为1000,enabled属性改为FALSE。用shape控件画出一个圆。

Dim g As Boolean

Dim x As Long

Private Sub Command1_Click()

Timer1.Enabled = True

End Sub

Private Sub Form_Load()

g = True

x = Shape1.Left

End Sub

Private Sub Timer1_Timer()

If g Then

x = x - 300

Else

x = x + 300

End If

If x < 0 Or x >(Me.ScaleWidth - Shape1.Width) Then

g = Not g

End If

Shape1.Move x

End Sub

在窗体中使用了一个按钮、一个计时器,并且用shape控件绘制了一个圆

 

原创粉丝点击