MS Access:表单计时器控件...我可以用它来设置例程中的时间间隙吗?

发布于 2024-10-03 23:32:09 字数 173 浏览 1 评论 0原文

只是想知道,如果我在启动屏幕上发生一些图形事件/动画,我可以使用计时器事件来简单地在一小段时间内打破例程。

基本上就像:

 -some action events
 DoEvents
 'some timer interval
 -more action code

Just wondering, if I have some graphical events/animation happening on a splash screen, can I use the timer event some how to simply break up the routine for a small amount of time.

basically like:

 -some action events
 DoEvents
 'some timer interval
 -more action code

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

烟若柳尘 2024-10-10 23:32:09

使用 Windows API 在代码段之间添加暂停。请参阅本页的 sSleep() 过程:使代码进入睡眠状态

Const clngMilliSeconds As Long = 10000 '(10 seconds) '
'some action events '
DoEvents
'some timer interval '
Call sSleep(clngMilliSeconds)
'more action code '

Use the Windows API to include a pause between code sections. See the sSleep() procedure at this page: Make code go to Sleep

Const clngMilliSeconds As Long = 10000 '(10 seconds) '
'some action events '
DoEvents
'some timer interval '
Call sSleep(clngMilliSeconds)
'more action code '
蔚蓝源自深海 2024-10-10 23:32:09

您可以将表单级别变量 Dim iStep as integer 组合起来,该变量将自动成为静态,并在您的 On Timer 过程中,如下所示:

Select Case iStep
    Case 1
        'do something'
    Case 2
        'do something else'
    Case 3
        'etc...'
End Select
iStep = iStep + 1

You could combine a form level variable Dim iStep as integer which will automatically be Static, and in your On Timer proc, something like:

Select Case iStep
    Case 1
        'do something'
    Case 2
        'do something else'
    Case 3
        'etc...'
End Select
iStep = iStep + 1
踏月而来 2024-10-10 23:32:09

在这种情况下,我认为最好通过在开始时将 Now() 存储到变量中来创建自己的计时器,并使用 DateDiff 检查所需的间隔,甚至直接减法,因为日期存储为数字。

Form Fade

从一个非常旧的库中挖掘出来,最近没有进行测试。
表单:

Option Compare Database
Dim gintC

Private Sub Form_Load()
Me.TimerInterval = 2
FadeForm Me, Fadezero, 1, 5
End Sub

Private Sub Form_Timer()
If IsEmpty(gintC) Then
    FadeForm Me, Fadein, 1, 15
End If
gintC = 1
Me.TimerInterval = 0
End Sub

模块:

Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
(ByVal hWnd As Long, ByVal nIndex As Long) As Long

Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Public Declare Function SetLayeredWindowAttributes Lib "user32" _
(ByVal hWnd As Long, ByVal crey As Byte, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long

Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Public Const GWL_EXSTYLE = (-20)

Public Const WS_EX_LAYERED = &H80000

Public Const WS_EX_TRANSPARENT = &H20&

Public Const LWA_ALPHA = &H2&

'Enum for determining the direction of the fade.

Public Enum FadeDirection

   Fadein = -1

   Fadeout = 0

   Fadezero = 1

   SetOpacity = 1

End Enum

Public Sub FadeForm(frm As Form, Optional Direction As FadeDirection = FadeDirection.Fadein, _
Optional iDelay As Integer = 0, Optional StartOpacity As Long = 5)

   Dim lOriginalStyle As Long
   Dim iCtr As Integer
   'You can only set a form's opacity if it's Popup property = True.
   If (frm.PopUp = True) Then
       'Get the form window’s handle, and remember its original style.
       lOriginalStyle = GetWindowLong(frm.hWnd, GWL_EXSTYLE)
       SetWindowLong frm.hWnd, GWL_EXSTYLE, lOriginalStyle Or WS_EX_LAYERED
       'If the form’s original style = 0, it hasn’t been faded since it was opened.
       'To get fading to work, we have to set its style to something other than zero.
       If (lOriginalStyle = 0) And (Direction <> FadeDirection.SetOpacity) Then
          'Recursively call this same procedure to set the value.
          FadeForm frm, SetOpacity, , StartOpacity
       End If
       'Depending on the direction of the fade...
       Select Case Direction
          Case FadeDirection.Fadezero
              iCtr = StartOpacity
              SetLayeredWindowAttributes frm.hWnd, 0, CByte(iCtr), LWA_ALPHA
          Case FadeDirection.Fadein
              'Just in case.
              If StartOpacity < 1 Then StartOpacity = 1
              'Fade the form in by varying its opacity
              'from the value supplied in 'StartOpacity'
              'to 255 (completely opaque).
              For iCtr = StartOpacity To 255 Step 1
                 SetLayeredWindowAttributes frm.hWnd, 0, CByte(iCtr), LWA_ALPHA
                 'Process any outstanding events.
                 DoEvents
                 'Wait a while, so the user can see the effect.
                 Sleep iDelay
              Next
          Case FadeDirection.Fadeout
              'Just in case.
              If StartOpacity < 6 Then StartOpacity = 255
              'Fade the form out by varying its opacity
              'from 255 to 1 (almost transparent).
              For iCtr = StartOpacity To 1 Step -1
                 SetLayeredWindowAttributes frm.hWnd, 0, CByte(iCtr), LWA_ALPHA
                 'Process any outstanding events.
                 DoEvents
                 'Wait a while, so the user can see the effect.
                 Sleep iDelay
              Next
          Case Else 'FadeDirection.SetOpacity.
              'Just in case.
              Select Case StartOpacity
                 Case Is < 1: StartOpacity = 1
                 Case Is > 255: StartOpacity = 255
              End Select
              'Set the form's opacity to a specific value.
              SetLayeredWindowAttributes frm.hWnd, 0, CByte(StartOpacity), LWA_ALPHA
                 'Process any outstanding events.
                 DoEvents
                 'Wait a while, so the user can see the effect.
                 Sleep iDelay
       End Select
   Else
       'The form’s Popup property MUST = True
       DoCmd.Beep
       MsgBox "The form's Popup property must be set to True.", vbOKOnly & vbInformation, "Cannot fade form"
   End If

End Sub

In this case, I think it would be better to create your own timer by storing Now() to a variable at the start, and checking for the intervals you want with DateDiff, or even straight subtraction, given that dates are stored as numbers.

Form Fade

Dug out of a very old library and not tested recently.
Form:

Option Compare Database
Dim gintC

Private Sub Form_Load()
Me.TimerInterval = 2
FadeForm Me, Fadezero, 1, 5
End Sub

Private Sub Form_Timer()
If IsEmpty(gintC) Then
    FadeForm Me, Fadein, 1, 15
End If
gintC = 1
Me.TimerInterval = 0
End Sub

Module:

Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
(ByVal hWnd As Long, ByVal nIndex As Long) As Long

Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Public Declare Function SetLayeredWindowAttributes Lib "user32" _
(ByVal hWnd As Long, ByVal crey As Byte, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long

Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Public Const GWL_EXSTYLE = (-20)

Public Const WS_EX_LAYERED = &H80000

Public Const WS_EX_TRANSPARENT = &H20&

Public Const LWA_ALPHA = &H2&

'Enum for determining the direction of the fade.

Public Enum FadeDirection

   Fadein = -1

   Fadeout = 0

   Fadezero = 1

   SetOpacity = 1

End Enum

Public Sub FadeForm(frm As Form, Optional Direction As FadeDirection = FadeDirection.Fadein, _
Optional iDelay As Integer = 0, Optional StartOpacity As Long = 5)

   Dim lOriginalStyle As Long
   Dim iCtr As Integer
   'You can only set a form's opacity if it's Popup property = True.
   If (frm.PopUp = True) Then
       'Get the form window’s handle, and remember its original style.
       lOriginalStyle = GetWindowLong(frm.hWnd, GWL_EXSTYLE)
       SetWindowLong frm.hWnd, GWL_EXSTYLE, lOriginalStyle Or WS_EX_LAYERED
       'If the form’s original style = 0, it hasn’t been faded since it was opened.
       'To get fading to work, we have to set its style to something other than zero.
       If (lOriginalStyle = 0) And (Direction <> FadeDirection.SetOpacity) Then
          'Recursively call this same procedure to set the value.
          FadeForm frm, SetOpacity, , StartOpacity
       End If
       'Depending on the direction of the fade...
       Select Case Direction
          Case FadeDirection.Fadezero
              iCtr = StartOpacity
              SetLayeredWindowAttributes frm.hWnd, 0, CByte(iCtr), LWA_ALPHA
          Case FadeDirection.Fadein
              'Just in case.
              If StartOpacity < 1 Then StartOpacity = 1
              'Fade the form in by varying its opacity
              'from the value supplied in 'StartOpacity'
              'to 255 (completely opaque).
              For iCtr = StartOpacity To 255 Step 1
                 SetLayeredWindowAttributes frm.hWnd, 0, CByte(iCtr), LWA_ALPHA
                 'Process any outstanding events.
                 DoEvents
                 'Wait a while, so the user can see the effect.
                 Sleep iDelay
              Next
          Case FadeDirection.Fadeout
              'Just in case.
              If StartOpacity < 6 Then StartOpacity = 255
              'Fade the form out by varying its opacity
              'from 255 to 1 (almost transparent).
              For iCtr = StartOpacity To 1 Step -1
                 SetLayeredWindowAttributes frm.hWnd, 0, CByte(iCtr), LWA_ALPHA
                 'Process any outstanding events.
                 DoEvents
                 'Wait a while, so the user can see the effect.
                 Sleep iDelay
              Next
          Case Else 'FadeDirection.SetOpacity.
              'Just in case.
              Select Case StartOpacity
                 Case Is < 1: StartOpacity = 1
                 Case Is > 255: StartOpacity = 255
              End Select
              'Set the form's opacity to a specific value.
              SetLayeredWindowAttributes frm.hWnd, 0, CByte(StartOpacity), LWA_ALPHA
                 'Process any outstanding events.
                 DoEvents
                 'Wait a while, so the user can see the effect.
                 Sleep iDelay
       End Select
   Else
       'The form’s Popup property MUST = True
       DoCmd.Beep
       MsgBox "The form's Popup property must be set to True.", vbOKOnly & vbInformation, "Cannot fade form"
   End If

End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文