这个屏保代码,如何能让图片的移动更平滑些呢?
以下代码可以实现一个图片在屏幕上移动,但是现在的问题是移动不够平滑,如何改可以实现呢?
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 SubPrivate 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

解决方案 »

  1.   

    最早的屏保为了防止CRT的烧屏,不过最有效的就是黑屏
    现在的屏保是用来张显个性了,已经不是最初的目的了
      

  2.   

    这是在抖啊........不会头晕么?想平滑,就需要在单位距离内移动的次数越多越好比如从0到100的X坐标,你一次移动10个坐标点,则移动次数是10,假如这一切在1秒内完成,就是10FPS,会有明显的跳动感,而且距离也太远,跳动感明显.如果你改为一次移动2,则看起来会非常平滑,因为这时一秒内已经移动了50次了,而且每次的距离非常接近,图象效果也是非常平滑的.....当然,会消耗更多的CPU资源.自己取舍吧.