How to delay the LostFocus Event in VB6

穿精又带淫゛_ 提交于 2020-01-15 19:33:11

问题


I'm having an issue with a process that involves the LostFocus event.

When the cursor loses focus from a particular textbox, I'm simply putting the focus back into that box.

My issue is removing focus long enough for the user to click a log out button. Is there a way to intercept the LostFocus event long enough to allow the user to click the log out button?


回答1:


Obviously I don't know the big picture here. But keeping only with what you said, the following does the trick. Effectively the event is delayed briefly, allowing the button to be clicked:

Option Explicit

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

Private Sub Text1_LostFocus()
   Sleep 100
   DoEvents

   Text1.SetFocus
End Sub



回答2:


With a combination of a Timer and another control that is outside of the borders of your form, you can achieve this.

Private Sub Text1_LostFocus()
    Combo1.SetFocus
    ReturnFocusTimer.Enabled = True
End Sub

Private Sub ReturnFocusTimer_Timer()
    ReturnFocusTimer.Enabled = False
    Text1.SetFocus
End Sub

In this example Combo1 is positioned beyond the bottom of the form. You can control the ReturnFocusTimer interval to however long you need.



来源:https://stackoverflow.com/questions/58736945/how-to-delay-the-lostfocus-event-in-vb6

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!