ex9.用top、left属性改变位置
Option Explicit
Dim myTop As Long, myLeft As Long
Private Sub Command1_Click()
'上移
With Image1
.Top = .Top - 100
End With
End Sub
Private Sub Command2_Click()
'下移
With Image1
.Top = .Top + 100
End With
End Sub
Private Sub Command3_Click()
'左移
With Image1
.Left = .Left - 100
End With
End Sub
Private Sub Command4_Click()
'右移
With Image1
.Left = .Left + 100
End With
End Sub
Private Sub Command5_Click()
'回到初始位置
With Image1
.Left = myLeft
.Top = myTop
End With
End Sub
Private Sub Form_Load()
With Image1
.Picture = LoadPicture(App.Path & "\chick.gif")
.Width = Me.Width / 8
.Height = Image1.Width
.Left = (Me.ScaleWidth - .Width) / 2
.Top = (Me.ScaleHeight - .Height) / 2
myLeft = .Left '记录初始位置
myTop = .Top
End With
End Sub
Tips:
top/left
属性是相对于控件所在容器原点(左上角)的位置,越往下top
值越大,越往右left
值越大- 注意将控件放置到容器中心的方法