〓〓〓〓 关 于 V B 简 单 的 问 题 〓〓〓〓

来源:百度知道 编辑:UC知道 时间:2024/05/29 13:39:39
我想弄个在屏幕上循环移动的VB窗体,事件是mousemove。
代码我也编出来了,感觉上是正确的,可是就是不成功。希望高手指点下。
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If (Form1.Top <> 1000 Or 6000) And (Form1.Left <> 1000 Or 9000) Then
Form1.Top = 1000
Form1.Left = 1000
End If

For i = 1 To 1
If Form1.Top = 1000 And Form1.Left = 1000 Then
Form1.Top = 1000: Form1.Left = 9000
Exit For
End If
If Form1.Top = 1000 And Form1.Left = 9000 Then
Form1.Top = 6000: Form1.Left = 9000
Exit For
End If
If Form1.Top = 6000 And Form1.Left = 9000 Then
Form1.Top = 6000: Form1.Left = 1000
Exit For
End If
If Form1.Top = 6000 And Form1.Left = 1000 Then
Form1.Top = 1000: Form1.Left = 1000
Exit For
End If
Next i

End Sub

顺便一提的是,为什么窗体名称是form1。可是事件对象前面却是form呢。。

Dim bM As Boolean

Private Sub Form_Activate()
bM = Not bM
Call MoveFrm
End Sub

Sub MoveFrm()
Dim iM As Long
Dim jM As Long
iM = 10
jM = 10
Do While bM
With Me
.Left = .Left + iM
.Top = .Top + jM
If .Left <= 0 Or (.Left + .Width) > Screen.Width Then iM = iM * -1
If .Top <= 0 Or (.Top + .Height) > Screen.Height Then jM = jM * -1
End With
DoEvents
Loop
End Sub

=================================
移动窗体的代码吗?试试这个,另外事件对象前面却是form的原因是,form是一个封装的类