代码如下:
Option Explicit
Dim iX As Integer
Dim iY As IntegerDim lScreenWidth As Long
Dim lScreenHeight As LongPrivate Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Private Sub Form_Load()
Dim l As Long
lScreenHeight = Screen.Height \ Screen.TwipsPerPixelY '桌面像素
lScreenWidth = Screen.Width \ Screen.TwipsPerPixelX
Me.Width = Image1.Width
Me.Height = Image1.Height
iX = 100
iY = 180
l = SetWindowPos(Me.hWnd, -1, 410, 550, 0, 0, 1) '最上面
End SubPrivate Sub Timer1_Timer()
Dim w As Long
Dim h As Long
w = Me.Width
h = Me.Height
Me.Left = Me.Left + iX
Me.Top = Me.Top + iY
If Me.Left + Me.Width > lScreenWidth * Screen.TwipsPerPixelX Or Me.Left < 0 Then iX = -iX
If Me.Top + Me.Height > lScreenHeight * Screen.TwipsPerPixelY Or Me.Top < 0 Then iY = -iY
End Sub
帮忙改成多图片浮动的呀,谢谢啊
能改成不规则浮动就最好啦,祝各位高人元旦快乐
Option Explicit
Dim iX As Integer
Dim iY As IntegerDim lScreenWidth As Long
Dim lScreenHeight As LongPrivate Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Private Sub Form_Load()
Dim l As Long
lScreenHeight = Screen.Height \ Screen.TwipsPerPixelY '桌面像素
lScreenWidth = Screen.Width \ Screen.TwipsPerPixelX
Me.Width = Image1.Width
Me.Height = Image1.Height
iX = 100
iY = 180
l = SetWindowPos(Me.hWnd, -1, 410, 550, 0, 0, 1) '最上面
End SubPrivate Sub Timer1_Timer()
Dim w As Long
Dim h As Long
w = Me.Width
h = Me.Height
Me.Left = Me.Left + iX
Me.Top = Me.Top + iY
If Me.Left + Me.Width > lScreenWidth * Screen.TwipsPerPixelX Or Me.Left < 0 Then iX = -iX
If Me.Top + Me.Height > lScreenHeight * Screen.TwipsPerPixelY Or Me.Top < 0 Then iY = -iY
End Sub
帮忙改成多图片浮动的呀,谢谢啊
能改成不规则浮动就最好啦,祝各位高人元旦快乐
Option ExplicitPrivate Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As LongPrivate Const SWP_NOSIZE As Long = &H1
Private Const HWND_TOPMOST As Long = -1
Dim l, w, h As LongPrivate Sub Form_Load() Me.ScaleMode = 3
Me.BorderStyle = 0
Me.Width = Image1.Width * Screen.TwipsPerPixelX
Me.Height = Image1.Height * Screen.TwipsPerPixelY
w = Me.Width
h = Me.Height
End SubPrivate Sub Timer1_Timer()
Me.Left = ((Screen.Width - Me.Width) \ Screen.TwipsPerPixelX) * Rnd()
Me.Top = ((Screen.Height - Me.Height) \ Screen.TwipsPerPixelY) * Rnd()
l = SetWindowPos(Me.hWnd, HWND_TOPMOST, Me.Left, Me.Top, w, h, SWP_NOSIZE) '最上面
End Sub