[Gambas-user] Resize event...

Doriano Blengino doriano.blengino at ...1909...
Wed Nov 12 09:46:24 CET 2008


Stephen Bungay ha scritto:
>    Well, after much consultation with Benoit I finally understand what 
> is going on and how to get around the problem.
>
>    For the benefit of anyone else who has been reading this thread, 
> Doraino and I were talking about instantiating a form inside a container 
> on another form and resizing that embedded form when the parent is resized.
>
>    In a nutshell the solution is to reference the instantiated form by 
> it's handle reference, created at the time of it being instantiated, and 
> NOT by its' name.
>
> For example, consider an application that has three form classes, 
> FormMain, FormX, and FormY. Form Main will contain a tabstrip and inside 
> that tabstrip we want to instantiate FormX on tabstrip index 0 and FormY 
> on tabstrip index 1. When we resize FormMain we want the embedded forms 
> in their tabs to resize appropriately. Our FormMain Class logic might 
> look like this;
>
> ' Gambas class file
> Private mFormInitialized as Boolean
> Private mhFormX As FormX
> Private mhFormY AS FormY
>
> Public Sub Form_Open()
>    InitializeControls
> End
>
>
> Private Sub InitializeControls()
>    TabStrip1.Index = 0
>    mhFormX = New FormX(TabStrip1)
>
>    TabStrip1.Index = 1
>    mhFormY = New FormY(TabStrip1)
>
>    TabStrip1.Index = 0
>
>    mFormInitialized = True
> End
>
>
> Public Sub Form_Resize()
>    With TabStrip1
>         .Width = .Parent.width - 10
>         .Height = .Parent.height - 20
>         mhFormX.Resize(TabStrip1.Width - 10, Tabstrip1.Height - 10)
>         mhFormY.Resize(TabStrip1.Width - 10, Tabstrip1.Height - 10)
>    End With
> End
>
>    The resize events in the forms referenced by mhFormX and mhFormY will 
> now fire as expected, the embedded forms resize events will now fire as 
> expected.
>
> Steve.
>   
Something strange is happening now.
I remember something wrong when embedding forms in tabstrip, for sure, 
and proof is you encounter the same problem. But yesterday I tried again 
to embed, and I found nothing wrong - both resize and open event were 
called in the embedded form (resize event was a little slower when 
embedded, but who cares). I tried both QT and GTK.
I never changed my version of Gambas, which is 2.0.0, so it is not a 
version issue. The only wrong thing is that a

    mhFormY = New FormY(TabStrip1) as "evformy"

doesn't work, and an observer is needed.

Now we come to your source. The "mFormInitialized" variable serves what 
purpose?
Then, where is the point to explicitly resize FormX and FormY in a 
manner so convolute? At the time the form is instanciated, it could be 
resized - so a single routine can be used to open as many forms are needed.
Next, who says that FormX wants to be resized to its 
"container.width-10" and "container.height-10"? When I say independence, 
I mean that FormMain has to embed another form, without knowing what 
that form will do with its geometry. If the explicit call to 
FormX.resize() has only the purpose to raise a resize event, well - I 
understand: when the resize event fires, the embedded form can do 
whatever it wants. But for me, the resize event was firing without any 
special processing.

All this seems messed, but I have a solution/request. How about an 
extended syntax to RAISE, which permit to send an event to a specified 
object? Like this:

    RAISE resize TO mhFormX

If the TO keyword is not specified, the event is sended, just like now, 
to the parent object.
Anyway, this should be not needed in this case - I repeat - for me the 
embedded forms receive form_open and form_resize - still I am sure that 
there was something wrong, but can't remember what...

This evening I will send my test project, if anybody can care.

Regards,
Doriano





More information about the User mailing list