这个屏保代码,如何能让图片的移动更平滑些呢?
这个屏保代码,如何能让图片的移动更平滑些呢?以下代码可以实现一个图片在屏幕上移动,但是现在的问题是移动不够平滑,如何改可以实现呢?
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Dim WithEvents lbl1 As Label
Dim WithEvents Timer1 As Timer
Dim WithEvents Timer2 As Timer
Dim WithEvents image1 As Image
Private Sub Form_Load()
Set lbl1 = Me.Controls.Add("VB.Label", "lbl1")
Set Timer1 = Me.Controls.Add("VB.Timer", "Timer1")
Set Timer2 = Me.Controls.Add("VB.Timer", "Timer2")
Set image1 = Me.Controls.Add("vb.image", "image1")
With Me
.BorderStyle = 0
.Caption = ""
.BackColor = &H0&
.KeyPreview = True
.WindowState = 2
End With
image1.Stretch = False
image1.Visible = True
image1.Picture = LoadPicture(App.Path & "\tmp.bmp")
With lbl1
.Visible = True
.AutoSize = True
.BackStyle = 0
.Caption = "美人如此多娇,引无数英雄竞折腰"
.Font.Size = 60
.Font.Name = "楷体_gb2312"
.Font.Bold = True
.ForeColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255)
.Move 0, 0
End With
Timer1.Enabled = True
Timer1.Interval = 1500
Timer2.Enabled = True
Timer2.Interval = 800
End Sub
Private Sub Timer1_Timer()
Dim i#, j#
i = Rnd * 15000
j = Rnd * 10000
image1.Move i, j
End Sub
Private Sub Timer2_Timer()
lbl1.ForeColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255)
End Sub
'在窗体上按下按键时退出程序
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Or KeyCode = 27 Then
Unload Me
End If
End Sub
'在窗体上移动鼠标或单击鼠标时退出程序
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Unload Me
End Sub