Tips03 : Focus changes without passing Exit event.
      ( Because I who am poor at English am translating into English while using translation software,  
        there may be an odd expression. The mistranslation revises it sequentially. )

  (Jpn. 1st Edition : 29 Nov. 2002 )
  (Eng. Translation: 30 Jul. 2014 )
In the situation that the focus changes from inside to outside of Frame control,
Exit event of TextBox control in Frame control may not fire.

This trouble happens in the following situation.
    a)  Press "Tab" or "Enter" key on TextBox of the Last Tab Order
        in Frame control.
    b)  Press "Shift + Tab" key in TextBox of the Top Tab Order in
        Frame control.
    c)  Mouse cick the control of outside of Frame control (It happens
        regardless of Tab Order).
    (Note : I explain it as an example in TextBox, but even other control is similar.)

When it became either of the following timing, Exit event that did not fire is late and fire.
    d)  When UserForm unloads, just before Terminate event.
    e)  When the focus changes to a certain control in Frame control again,
        between Enter event of Frame control and Enter event of the control.
        (In addition, it does not fire when it returned to the same control when it left Frame.
          Enter event of the control does not fire, too.)

Video Capture ( Tips03_FrameFocus.mp4   633KB )

Inspection macro workbook ( EnterExitEvent.xlsm  31KB )

The solution to this obstacle are ....
    f) Do not use the Enter/Exit events for the control in the Frame control.
    g) Substitute a Border line of the Label control for the Frame control.
              [ Caption : nothing ]
              [ BackStyle : fmBackStyleTransparent ]
              [ SpecialEffect : fmSpecialEffectEtched ]
              [ Format menu / Order / Send to Back]

I explain the details by the following control layout.

+--------------- Frame1 ----------------------+
I [TextBox2] [TextBox3] [TextBox4] [TextBox5] I

Tab Order in UserForm:TextBox1 -> Frame1 -> TextBox6
Tab Order in Frame1:TextBox2 -> TextBox3 -> TextBox4 -> TextBox5

-- Focus changes from inside to outside of Frame control by Tab key --
Transition of Focus
    TextBox5 -> TextBox6 -> TextBox1 -> TextBox2

Transition of Event
    Box5_Enter -> (nothing!) -> Frame1_Exit -> Box6_Enter
      -> Box6_Exit -> Box1_Enter -> Box1_Exit -> Frame1_Enter
        -> Box5_Exit (in this timing ?) -> Box2_Enter

-- Focus goes in and out with Frame control (Tab and Shift+Tab) --
Transition of Focus
    TextBox5 -> TextBox6 -> TextBox5 -> TextBox6 -> TextBox5 -> TextBox6

Transition of Event
  (Enter and Exit event of TextBox5 does not fire even if repeated how many times.)
    Box5_Enter -> Frame1_Exit -> Box6_Enter -> Box6_Exit
      -> Frame1_Enter -> Frame1_Exit -> Box6_Enter -> Box6_Exit
        -> Frame1_Enter -> Frame1_Exit -> Box6_Enter

-- Source of the problem --
About focus transition of "Inside to Outside of Frame" and "Outside to Inside of Frame",
it is thought that it is treated as follows.

The focus information is managed independently in UserForm and Frame control.
(The TAB order becomes independent, too)

Three times of Focus transition following (f) is only one Focus transition following (g)
for Frame control.
  f)  TextBox5(inside) -> TextBox6(outside) -> TextBox1(outside) -> TextBox2(inside)
  g)  TextBox5(inside) -> TextBox2(inside)

Frame control does not recognize Focus transition of the following square bracket.
As a viewpoint of Frame control, it do not recognize that other control cuts in between,
and Box5_Exit fires in right timing (just before Box2_Enter).

    Box5_Enter -> [ -> -> -> ] -> Box5_Exit -> Box2_Enter
    [ -> Frame1_Exit -> Box6_Enter -> ...... -> Frame1_Enter -> ] 

This is the reason that Box5_Exit fires in a strange timing.

We can understand two remaining case ((d) and (e) mentioned above) for this reason.
In other words, it recognize that Focus does not change from the present control in
Frame control at all.

-- Stranger event transition happens in Mouse-Click --

When a mouse clicks TextBox4(inside), the following event transition happens.

Transition of Focus
    TextBox1(outside) -- Mouse Click --> TextBox4(inside)

Transition of Event
    Box1_Exit -> Frame1_Enter -> Box2_Enter -> Box2_Exit -> Box4_Enter

Just before Enter event of the target control (TextBox4), Enter and Exit event of the
control (TextBox2) fires.  TextBox2 is control of the top Tab Order in Frame control.

In the case of Mouse Click, Enter and Exit event of the control of the top
Tab Order in Frame control cuts in.

These problems are not only Frame control.
It happens by the MultiPage control, too.

[ AddinBox Home (Japanese) ]  [ English Home ]  

AddinBox ( K.Tsunoda in Japan ) CopyRight(C) 2014 Allrights Reserved.