# Making a frame stay on top sometimes

**URL:** <https://www.ruby-forum.com/t/making-a-frame-stay-on-top-sometimes/153725>\
**Category:** wxRuby\
**Created:** [November 20, 2008, 3:39pm UTC](https://www.ruby-forum.com/t/making-a-frame-stay-on-top-sometimes/153725 "2008-11-20T15:39:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![erubin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/82dd89/32.png) [@erubin](https://www.ruby-forum.com/u/erubin)\
**Post date:** [November 20, 2008, 3:39pm UTC](https://www.ruby-forum.com/t/making-a-frame-stay-on-top-sometimes/153725/1 "2008-11-20T15:39:12Z")

</div>

I’m using STAY\_ON\_TOP in the style when I create my Frame app so it is  
always on top, and it works fine. What I want, though, is for the Frame  
to  
stay on top under some conditions, but behave normally under other  
conditions. I don’t see any set\_style method for Frame that would let  
me  
turn the STAY\_ON\_TOP behavior on and off dynamically. Is there any way  
to  
do this?

Eric R.

---

<div class="post-metadata">

**Author:** ![erubin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/82dd89/32.png) [@erubin](https://www.ruby-forum.com/u/erubin)\
**Post date:** [November 20, 2008, 3:50pm UTC](https://www.ruby-forum.com/t/making-a-frame-stay-on-top-sometimes/153725/2 "2008-11-20T15:50:59Z")

</div>

Hi Eric

Eric R. wrote:

> I’m using STAY\_ON\_TOP in the style when I create my Frame app so it is  
> always on top, and it works fine. What I want, though, is for the  
> Frame to stay on top under some conditions, but behave normally under  
> other conditions. I don’t see any set\_style method for Frame that  
> would let me turn the STAY\_ON\_TOP behavior on and off dynamically. Is  
> there any way to do this?

From my reading of wxWidgets discussions, there’s no way to change the  
style flags of a Window (inc Frame) after it’s been created. This is  
because changes are not guaranteed to be honoured on all platforms.

The way round this in your circumstance might be to have two frames,  
with one hidden and one shown at any time. One has the STAY\_ON\_TOP  
style, the other not. When you want to change the STAY\_ON\_TOP behaviour:

1. hide the currently shown frame
2. reparent that frame’s top-level content (eg Panel) to the other frame
3. move the frame you’re about to show to the same size and position
4. show the previously hidden frame

hth  
alex

---

<div class="post-metadata">

**Author:** ![erubin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/82dd89/32.png) [@erubin](https://www.ruby-forum.com/u/erubin)\
**Post date:** [November 20, 2008, 4:04pm UTC](https://www.ruby-forum.com/t/making-a-frame-stay-on-top-sometimes/153725/3 "2008-11-20T16:04:34Z")

</div>

Thanks, but I just noticed that there is a Window#set\_window\_style\_flag  
which seems like it would do what I want. I think I’ll give that a try.  
If  
it doesn’t work I might try your two frames solution.

Eric

---

<div class="post-metadata">

**Author:** ![erubin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/82dd89/32.png) [@erubin](https://www.ruby-forum.com/u/erubin)\
**Post date:** [November 20, 2008, 4:15pm UTC](https://www.ruby-forum.com/t/making-a-frame-stay-on-top-sometimes/153725/4 "2008-11-20T16:15:45Z")

</div>

Looks like Window#set\_window\_style\_flag allows me to turn STAY\_ON\_TOP on  
and  
off (in MS Windows).

Eric

---

<div class="post-metadata">

**Author:** ![erubin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/82dd89/32.png) [@erubin](https://www.ruby-forum.com/u/erubin)\
**Post date:** [November 20, 2008, 4:39pm UTC](https://www.ruby-forum.com/t/making-a-frame-stay-on-top-sometimes/153725/5 "2008-11-20T16:39:20Z")

</div>

Eric R. wrote:

> Looks like Window#set\_window\_style\_flag allows me to turn STAY\_ON\_TOP on and  
> off (in MS Windows).

Ah, thanks, I thought there was some method that did this but couched in  
warnings about changes to some flags on some platforms not being  
honoured.

Useful to know that this one is - much neater solution.

alex
