首页 热点资讯 义务教育 高等教育 出国留学 考研考公

vb屏幕保护代码

发布网友 发布时间:2022-04-23 10:31

我来回答

4个回答

热心网友 时间:2023-10-11 13:05

改成这样子就没问题了:
Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
Dim WithEvents Label1 As Label
Dim WithEvents Timer1 As Timer
Dim X1%, Y1%, X2%, Y2%, I%, k%, orignX&, orignY&, J As Boolean
Dim Gaokao As Date, A As Integer, B As Integer, C As Integer, D As Integer

Private Sub Form_Load()
Gaokao = #6/6/2011#
A = DateDiff("d", Now, Gaokao)
B = 23 - Hour(Time)
C = 59 - Minute(Time)
D = 60 - Second(Time)
If D = 60 Then
D = 0
C = C + 1
End If
If C = 60 Then
C = 0
B = B + 1
End If
If B < 0 Then
B = 24 + B
A = A - 1
End If

Set Label1 = Me.Controls.Add("VB.Label", "Label1")
Set Timer1 = Me.Controls.Add("VB.Timer", "Timer1")
Set Timer1 = Me.Controls.Add("VB.Timer", "Timer2")

With Me
.BorderStyle = 0
.Caption = ""
.BackColor = &H0&
.FillColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255)
.ForeColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255)
.DrawMode = 13
.DrawWidth = 2
.FillStyle = 7
.KeyPreview = True
.WindowState = 2
.Move 0, 0, Screen.Width, Screen.Height
End With
With Label1
.Visible = True
.AutoSize = True
.BackStyle = 0
.Caption = A & "天" & B & "小时" & C & "分钟" & D & "秒"
.Font.Size = 60
.ForeColor = &HFF00&

.Top = Me.Height / 2 - Label1.Height / 2
.Left = Me.Width / 2 - Label1.Width / 2
End With
Timer1.Enabled = True
Timer1.Interval = 10
SetCursorPos Screen.Width \ 15, 0
orignX = Screen.Width \ 15: orignY = 0

End Sub

Private Sub Form_Activate()

I = 100: k = 100
X1 = Me.Width / 2: Y1 = Me.Height / 3
X2 = X1: Y2 = Y1
End Sub

Private Sub Form_Unload(Cancel As Integer)

Set Form1 = Nothing
End
End Sub

Private Sub Timer1_Timer()

A = DateDiff("d", Now, Gaokao)
B = 23 - Hour(Time)
C = 59 - Minute(Time)
D = 60 - Second(Time)
If D = 60 Then
D = 0
C = C + 1
End If
If C = 60 Then
C = 0
B = B + 1
End If
If B < 0 Then
B = 24 + B
A = A - 1
End If
Label1.Caption = A & "天" & B & "小时" & C & "分钟" & D & "秒"

If Y1 <= Me.Height - 1200 Then
X1 = X1 + k: Y1 = Y1 - I
X2 = X2 - k: Y2 = Y2 - I
I = I - 2
k = IIf(Y1 <= Me.Height / 3, k - 1, IIf(Y1 >= Me.Height \ 3, k - 5, k))
Else
I = 100: k = 100
X1 = Me.Width / 2: Y1 = Me.Height / 3
X2 = X1: Y2 = Y1
Me.FillColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255)
Me.ForeColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255)
End If
Me.DrawWidth = 3
Me.PSet (Rnd * Me.Width, Rnd * Me.Height), RGB(Rnd * 225, Rnd * 225, Rnd * 225)
Me.DrawWidth = 2

End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode <> 0 Then Unload Me

End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

If Button <> 0 Or Abs(X \ 15 - orignX) >= 3 Or Abs(Y \ 15 - orignY) > 3 Then Unload Me
End Sub

已经运行过了!!

热心网友 时间:2023-10-11 13:06

vb我没有研究过,但是类似的程序倒是看到过。调用系统时间显示在程序界面上,然后剩下一个定时刷新界面的问题。这里好像可以用到递归,直到捕获鼠标或者键盘变化就跳出递归。
这只是我个人的想法,既然没办法在代码逻辑上帮到你也只好求其次了。

热心网友 时间:2023-10-11 13:06

把label1.Caption = a & "天" & b & "小时" & c & "分钟" & d & "秒"
加入到timer1的事件中即可

热心网友 时间:2023-10-11 13:07

rivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

If Button <> 0 Or Abs(X \ 15 - orignX) >= 3 Or Abs(Y \ 15 - orignY) > 3 Then Unload Me
End Sub

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com