3

当用户在子表单上的记录之间切换时,我希望另一个字段临时突出显示以吸引眼球以提醒用户它已更改。

我认为这会起作用:

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

Private Sub Form_Current()
    Form_frm_Codes.txtCodeToAdd = Me.Code.Value
    Form_frm_Codes.txtCodeToAdd.BackColor = RGB(0, 0, 255)
    Sleep (500)
    Form_frm_Codes.txtCodeToAdd.BackColor = RGB(255, 255, 255)
End Sub

睡眠功能往往会使程序暂停半秒钟,但我没有立即看到蓝色的变化。

有什么想法甚至更好的方法来实现这一目标吗?

4

1 回答 1

1

而不是使用 API 尝试下面的代码

Private Sub Form_Current()
    Form_frm_Codes.txtCodeToAdd = Me.Code.Value
    Form_frm_Codes.txtCodeToAdd.BackColor = RGB(0, 0, 255)
    delay 5
    Form_frm_Codes.txtCodeToAdd.BackColor = RGB(255, 255, 255)
End Sub

Private Sub delay(seconds As Long)
    Dim endTime As Date
    endTime = DateAdd("s", seconds, Now())
    Do While Now() < endTime
        DoEvents
    Loop
End Sub

或在睡眠前添加 DoEvents 以更新屏幕。

Private Sub Form_Current()
    Form_frm_Codes.txtCodeToAdd = Me.Code.Value
    Form_frm_Codes.txtCodeToAdd.BackColor = RGB(0, 0, 255)
    DoEvents
    Sleep (500)
    Form_frm_Codes.txtCodeToAdd.BackColor = RGB(255, 255, 255)
End Sub
于 2013-04-30T07:01:42.457 回答