# Event for container coming to front

**URL:** <https://forum.xojo.com/t/event-for-container-coming-to-front/23142>\
**Category:** General\
**Created:** [March 21, 2015, 9:34am UTC](https://forum.xojo.com/t/event-for-container-coming-to-front/23142 "2015-03-21T09:34:55Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Beatrix\_Willius](https://forum.xojo.com/user_avatar/forum.xojo.com/beatrix_willius/32/282_2.png) [@Beatrix\_Willius](https://forum.xojo.com/u/Beatrix_Willius)\
**Post date:** [March 21, 2015, 9:34am UTC](https://forum.xojo.com/t/event-for-container-coming-to-front/23142/1 "2015-03-21T09:34:55Z")

</div>

Can I get/make/fake an event when a container comes to front? I’ve got several containercontrols on a page panel. A new design needs to disable and later enable a button on the main window when a specific containercontrol comes to front. I could use a paint event but this is so unelegant.

---

<div class="post-metadata">

**Author:** ![Markus\_Winter](https://forum.xojo.com/user_avatar/forum.xojo.com/markus_winter/32/144_2.png) [@Markus\_Winter](https://forum.xojo.com/u/Markus_Winter)\
**Post date:** [March 21, 2015, 9:46am UTC](https://forum.xojo.com/t/event-for-container-coming-to-front/23142/2 "2015-03-21T09:46:13Z")

</div>

Does only the ContainerControl change or the PagePanel too? In which case the PagePanel.Change event should work 

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [March 21, 2015, 9:46am UTC](https://forum.xojo.com/t/event-for-container-coming-to-front/23142/3 "2015-03-21T09:46:15Z")

</div>

> [@175543:@Beatrix Willius](#):
>
> Can I get/make/fake an event when a container comes to front? I’ve got several containercontrols on a page panel. A new design needs to disable and later enable a button on the main window when a specific containercontrol comes to front. I could use a paint event but this is so unelegant.

Activate ?

---

<div class="post-metadata">

**Author:** ![Eli\_Ott](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/5f8ce5/32.png) [@Eli\_Ott](https://forum.xojo.com/u/Eli_Ott)\
**Post date:** [March 21, 2015, 10:18am UTC](https://forum.xojo.com/t/event-for-container-coming-to-front/23142/4 "2015-03-21T10:18:22Z")

</div>

> [@175545:@Michel Bujardet](#):
>
> Activate ?

This event is not raised. It only shows up as event in the IDE because ContainerControl is a subclass of Window. Same for Deactivate.

---

<div class="post-metadata">

**Author:** ![Beatrix\_Willius](https://forum.xojo.com/user_avatar/forum.xojo.com/beatrix_willius/32/282_2.png) [@Beatrix\_Willius](https://forum.xojo.com/u/Beatrix_Willius)\
**Post date:** [March 21, 2015, 10:21am UTC](https://forum.xojo.com/t/event-for-container-coming-to-front/23142/5 "2015-03-21T10:21:51Z")

</div>

@Markus: the pagepanel is on the window. I want the information to travel up and not down.

@Michel: neither Activate nor GetFocus work. They don’t fire.

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [March 21, 2015, 10:25am UTC](https://forum.xojo.com/t/event-for-container-coming-to-front/23142/6 "2015-03-21T10:25:19Z")

</div>

[quote=175552:@Beatrix Willius]@Markus: the pagepanel is on the window. I want the information to travel up and not down.

@Michel: neither Activate nor GetFocus work. They don’t fire.[/quote]

You are not manipulating the zorder, right ? When you say “come up front”, you mean the page becomes visible ?

If so, why not simply use the PagePanel Change event and PanelIndex ?

---

<div class="post-metadata">

**Author:** ![Beatrix\_Willius](https://forum.xojo.com/user_avatar/forum.xojo.com/beatrix_willius/32/282_2.png) [@Beatrix\_Willius](https://forum.xojo.com/u/Beatrix_Willius)\
**Post date:** [March 21, 2015, 10:34am UTC](https://forum.xojo.com/t/event-for-container-coming-to-front/23142/7 "2015-03-21T10:34:30Z")

</div>

@Michel: nope, I’m not manipulating the zorder. I just want to have the containercontrol announce to the window that it is on “I’m now there”. The pagepanel change event - of course - also will work.

But I’m not sure if the design and the number of pages on the page panel will stay. Therefore, I’d rather not hardcode the number of the pagepanel. The window is a wizard style window where the steps may change depending on the situation.

Once upon a time there was some code from Charles Yeomans called “Better ContainerControl”. This did what I wanted. Unfortunately, this makes a nice infinite loop and then a crash since Xojo 2015r1.

---

<div class="post-metadata">

**Author:** ![Markus\_Winter](https://forum.xojo.com/user_avatar/forum.xojo.com/markus_winter/32/144_2.png) [@Markus\_Winter](https://forum.xojo.com/u/Markus_Winter)\
**Post date:** [March 21, 2015, 10:45am UTC](https://forum.xojo.com/t/event-for-container-coming-to-front/23142/8 "2015-03-21T10:45:20Z")

</div>

> [@175554:@Beatrix Willius](#):
>
> .Once upon a time there was some code from Charles Yeomans called “Better ContainerControl”. This did what I wanted. Unfortunately, this makes a nice infinite loop and then a crash since Xojo 2015r1.

Where is the code available? Maybe someine can figure out how to fix it?

---

<div class="post-metadata">

**Author:** ![Eli\_Ott](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/5f8ce5/32.png) [@Eli\_Ott](https://forum.xojo.com/u/Eli_Ott)\
**Post date:** [March 21, 2015, 10:48am UTC](https://forum.xojo.com/t/event-for-container-coming-to-front/23142/9 "2015-03-21T10:48:45Z")

</div>

> [@175554:@Beatrix Willius](#):
>
> Once upon a time there was some code from Charles Yeomans called “Better ContainerControl”

It has been in MacOSLib as an example since a few years.

The problem with it is that it is subclass of ContainerControl which shadows the Visible property. So to work properly you always need to cast the ContainerControl to BetterContainerControl ot the Visible property of ContainerControl will be called  thereby omitting the following code:

`ComputedProperty Visible As Boolean
  Get
    return ContainerControl(me).Visible
  End Get
  Set
    if value = me.Visible then
      return
    end if
    if value then
      me.Show // Raises a VisibilityChanged event
    else
      me.Hide // Raises a VisibilityChanged event
    end if
  End Set
EndComputedProperty`

> [@175554:@Beatrix Willius](#):
>
> Unfortunately, this makes a nice infinite loop and then a crash since Xojo 2015r1.

Looking at code of BetterContainerControl in MacOSLib I doubt this is really an error in BetterContainerControl. Do you have a screenshot of the code where this happens?

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [March 21, 2015, 11:05am UTC](https://forum.xojo.com/t/event-for-container-coming-to-front/23142/10 "2015-03-21T11:05:32Z")

</div>

[quote=175554:@Beatrix Willius]@Michel: nope, I’m not manipulating the zorder. I just want to have the containercontrol announce to the window that it is on “I’m now there”. The pagepanel change event - of course - also will work.

But I’m not sure if the design and the number of pages on the page panel will stay. Therefore, I’d rather not hardcode the number of the pagepanel. The window is a wizard style window where the steps may change depending on the situation.

Once upon a time there was some code from Charles Yeomans called “Better ContainerControl”. This did what I wanted. Unfortunately, this makes a nice infinite loop and then a crash since Xojo 2015r1.[/quote]

Your idea of the Paint even seems to work.

The issue with a container control is that it does not have a PanelIndex property. I tried to cast it as RectControl but got an illegal cast exception.

For any other control, you can compare control.PanelIndex with PagePanel(control.Parent).Value and if it is the same the control is displayed. The best I could find is to place the instance of the ContainerControl on a Canvas, which has PagePanel.

---

<div class="post-metadata">

**Author:** ![Markus\_Winter](https://forum.xojo.com/user_avatar/forum.xojo.com/markus_winter/32/144_2.png) [@Markus\_Winter](https://forum.xojo.com/u/Markus_Winter)\
**Post date:** [March 21, 2015, 11:50am UTC](https://forum.xojo.com/t/event-for-container-coming-to-front/23142/11 "2015-03-21T11:50:41Z")

</div>

Silly question (not on my Mac for a few weeks): could you not add a property PanelIndex to the ContainerControl and set it when the ContainerControl is initiated?

---

<div class="post-metadata">

**Author:** ![Antonio\_Rinaldi](https://forum.xojo.com/user_avatar/forum.xojo.com/antonio_rinaldi/32/331_2.png) [@Antonio\_Rinaldi](https://forum.xojo.com/u/Antonio_Rinaldi)\
**Post date:** [March 21, 2015, 11:59am UTC](https://forum.xojo.com/t/event-for-container-coming-to-front/23142/12 "2015-03-21T11:59:28Z")

</div>

The containerControl has a TabPanelIndex property (that’s used on embedWithin for example)

it’s 0 for a CC on a window  
it’s panelIndex+1 for a page or tab panel

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [March 21, 2015, 12:25pm UTC](https://forum.xojo.com/t/event-for-container-coming-to-front/23142/13 "2015-03-21T12:25:53Z")

</div>

[quote=175564:@Antonio Rinaldi]The containerControl has a TabPanelIndex property (that’s used on embedWithin for example)

it’s 0 for a CC on a window  
it’s panelIndex+1 for a page or tab panel[/quote]

Oh you are right. Except it is not PanelIndex, but the deprecated TabPanelIndex which is 1 based. Thank you, though. Guess Xojo should update its event name.

This in the Change event of the TabPanel very nicely spots when the Container Control is displayed :

` if ContainerControl11.TabPanelIndex-1 = me.Value then
    msgbox "You win !"
  end if`

> [@175562:@Markus Winter](#):
>
> Silly question (not on my Mac for a few weeks): could you not add a property PanelIndex to the ContainerControl and set it when the ContainerControl is initiated?

Your question is not silly, but there is simply no event in ContainerControl that fires when it is displayed. Except for Paint, but it fires so often it is a mess.

---

<div class="post-metadata">

**Author:** ![Antonio\_Rinaldi](https://forum.xojo.com/user_avatar/forum.xojo.com/antonio_rinaldi/32/331_2.png) [@Antonio\_Rinaldi](https://forum.xojo.com/u/Antonio_Rinaldi)\
**Post date:** [March 21, 2015, 12:34pm UTC](https://forum.xojo.com/t/event-for-container-coming-to-front/23142/14 "2015-03-21T12:34:32Z")

</div>

I wrote panelIndex+1 to say that it’s current panel number+1 not that the property is PanelIndex.

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [March 21, 2015, 12:45pm UTC](https://forum.xojo.com/t/event-for-container-coming-to-front/23142/15 "2015-03-21T12:45:18Z")

</div>

> [@175572:@Antonio Rinaldi](#):
>
> I wrote panelIndex+1 to say that it’s current panel number+1 not that the property is PanelIndex.

I understand. It is somewhat inconsistent for Xojo to keep TabPanelIndex for ContainerControl while having PanelIndex for other controls, though. I missed it when I tried to have CC.PanelIndex autocomplete and saw it was not there. I should have looked at the LR instead.

---

<div class="post-metadata">

**Author:** ![Beatrix\_Willius](https://forum.xojo.com/user_avatar/forum.xojo.com/beatrix_willius/32/282_2.png) [@Beatrix\_Willius](https://forum.xojo.com/u/Beatrix_Willius)\
**Post date:** [March 21, 2015, 1:30pm UTC](https://forum.xojo.com/t/event-for-container-coming-to-front/23142/16 "2015-03-21T13:30:14Z")

</div>

Thanks for the ideas, guys.

Regarding BetterContainerControl: it makes a StackOverflowException in the Shown event. My guess it that the order of events changed internally. You can find an example here: [https://conbr.io/d/sEey5rsw](https://conbr.io/d/sEey5rsw) .

---

<div class="post-metadata">

**Author:** ![Eli\_Ott](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/5f8ce5/32.png) [@Eli\_Ott](https://forum.xojo.com/u/Eli_Ott)\
**Post date:** [March 21, 2015, 6:30pm UTC](https://forum.xojo.com/t/event-for-container-coming-to-front/23142/18 "2015-03-21T18:30:11Z")

</div>

This should work in 2015r1:

[code]Class BetterContainerControl Inherits ContainerControl

Event Open()  
Event VisibilityChanged()  
Event VisibilityChanging()

Sub Open()  
Self.Visible = True  
RaiseEvent Open()  
End

Sub Hide()  
If Self.Visible Then  
RaiseEvent VisibilityChanging()  
Window(Self).Hide()  
RaiseEvent VisibilityChanged()  
End  
End

Sub Show()  
? If Not Self.Visible Then  
RaiseEvent VisibilityChanging()  
Window(Self).Show()  
RaiseEvent VisibilityChanged()  
End  
End

Property Visible As Boolean  
Get  
Return ContainerControl(Self).Visible  
End  
Set  
If value \<\> ContainerControl(Self).Visible Then  
If value Then  
Show()  
Else  
Hide()  
End  
End  
End  
End[/code]

---

<div class="post-metadata">

**Author:** ![Beatrix\_Willius](https://forum.xojo.com/user_avatar/forum.xojo.com/beatrix_willius/32/282_2.png) [@Beatrix\_Willius](https://forum.xojo.com/u/Beatrix_Willius)\
**Post date:** [March 22, 2015, 8:18am UTC](https://forum.xojo.com/t/event-for-container-coming-to-front/23142/19 "2015-03-22T08:18:24Z")

</div>

@Eli: thanks! Scratching head: what is the difference? Why does your version work and my version crash? There are a couple of raiseevents and self is used instead of me.

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 5:41pm UTC](https://forum.xojo.com/t/event-for-container-coming-to-front/23142/20 "2020-10-29T17:41:55Z")

</div>


