# Re: 有 lostfocus , 无 getfocus

Posted by 洪扬 on January 01, 1999 at 22:04:04:

In Reply to: 有 lostfocus , 无 getfocus posted by jutso on December 31, 1998 at 14:42:24:

: 我有一个 test 用的程式如下：

: VERSION 5.00
: Begin VB.Form Form1
: Caption = "Form1"
: ClientHeight = 2520
: ClientLeft = 48
: ClientTop = 312
: ClientWidth = 3744
: LinkTopic = "Form1"
: ScaleHeight = 2520
: ScaleWidth = 3744
: StartUpPosition = 3 '系统预设值
: Begin VB.TextBox Text2
: Height = 372
: Left = 600
: TabIndex = 1
: Text = "Text2"
: Top = 1080
: Width = 2532
: End
: Begin VB.TextBox Text1
: Height = 372
: Left = 600
: TabIndex = 0
: Text = "Text1"
: Top = 360
: Width = 2532
: End
: End
: Attribute VB_Name = "Form1"
: Attribute VB_GlobalNameSpace = False
: Attribute VB_Creatable = False
: Attribute VB_PredeclaredId = True
: Attribute VB_Exposed = False
: Option Explicit

:
: Private Sub Text1_GotFocus()

: Debug.Print "text1 getfocus"

: End Sub

: Private Sub Text1_LostFocus()

: Debug.Print "text1 lostfocus"
:
: MsgBox "text1 lost focus"
:
: Text1.SetFocus
:
: DoEvents
:

: End Sub

:
: Private Sub Text2_GotFocus()

: Debug.Print "text2 getfocus"

: End Sub

: Private Sub Text2_LostFocus()

: Debug.Print "text2 lostfocus"
:
: MsgBox "text2 lost focus"
:
: Text2.SetFocus
: DoEvents

: End Sub

: 执行后，点一下 text2，只是轮流出现 text1 lostfocus 跟 text2 lostfocus，
: 却都没出现 getfocus 事件，请问没有 getfocus ，怎么会有一大堆
: lostfocus？

把 MsgBox() 拿掉之后就正常了!
程式一执行之后GetFocus, LostFocus轮流出现,
直到堆叠用尽! 程式中断为止!
问题是出在 MsgBox() 身上!

Follow Ups: