# VB 圖形移動問題

Private Sub Command1_Click()

If Option3.Value = True Then

Image1.Left = Image1.Left - Speed

Else: Image1.Left = ScaleWidth: End If

If Image1.Top >= -Image1.Height Then

Image1.Top = Image1.Top - Speed

Else: Image1.Top = ScaleHeight: End If

### 1 個解答

• 世賢
Lv 7
1 0 年前
最佳解答

Option Explicit

Dim Speed As Integer

Private Sub Command1_Click()

Dim opts As Integer

If Option1.Value = True Then opts = 1

If Option2.Value = True Then opts = 2

If Option3.Value = True Then opts = 3

If Option4.Value = True Then opts = 4

Select Case opts

Case 1 '左上

Image1.Left = Image1.Left - Speed

Image1.Top = Image1.Top - Speed

Case 2 '正下方

Image1.Top = Image1.Top + Speed

Case 3 '左方

Image1.Left = Image1.Left - Speed

Case 4 '右下方

Image1.Left = Image1.Left + Speed

Image1.Top = Image1.Top + Speed

End Select

If Image1.Left < 0 Then Image1.Left = Me.ScaleWidth - Image1.Width

If Image1.Top < 0 Then Image1.Top = Me.ScaleHeight - Image1.Height

If Image1.Left > Me.ScaleWidth - Image1.Width Then Image1.Left = 0

If Image1.Top > Me.ScaleHeight - Image1.Height Then Image1.Top = 0

End Sub

Speed = Screen.TwipsPerPixelX * 15

Option1.Caption = "左上"

Option2.Caption = "正下方"

Option3.Caption = "左方"

Option4.Caption = "右下方"

End Sub