B4J Question SetWindowSizeLimits

LucaMs

Expert
Licensed User
Longtime User
At first glance SetWindowSizeLimits doesn't seem to work perfectly, but I suppose that with it you set the minimum and maximum of the internal size of the Form, not the total ones, including the borders. This is probably because there are various Form styles, even without borders.

So, assuming what I just wrote, I tried this code:
B4X:
    Dim FormVertBorderSize As Int = frm.WindowWidth - frm.Width
    Dim FormHorBorderSize As Int = frm.WindowHeight - frm.Height
    frm.SetWindowSizeLimits(515 + FormVertBorderSize, 410 + FormHorBorderSize, fx.PrimaryScreen.MaxX + FormVertBorderSize, fx.PrimaryScreen.MaxY + FormHorBorderSize)

but both that variables return zero (the Form style is Default, with borders) and, for example, the minimum height allowed is 372 instead of the desired 410.

Log(frm.WindowWidth) writes a not so nice: NaN = Not a Number :confused:
I suppose (too many suppositions) I have to move that code where the Form has already been displayed but I don't think there is an ideal event, such as the Appear event of the B4XPages would be. (Don't suggest me to use the B4XPages, which I love and which I myself always suggest; that's what I did initially and then I had to redo the project without them).

I solved setting:
B4X:
    FormVertBorderSize = 16
    FormHorBorderSize = 38

but that's not the best way to do it.
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
I forgot to write that I create that Form in the Initialize routine of a class. This is why the Form is not yet "ready" there.
I can use a CallSubDelayed to call a routine which sets the Form size limits, but since the routine will be executed only upon completion of the initialization, I will have to be very careful not to run "compromising" code first.

In short: it would be useful to have an event like Appear by B4XPages.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Um... but then I don't understand why this part works:

B4X:
Public Sub Initialize (Parent As Form)
    frm.Initialize("frm", 900, 460)
    frm.RootPane.LoadLayout("MyLayout") ' <----------- ???????
    frm.SetOwner(Parent)

?


Note that it is not possible to add a Sleep(0) since Initialize cannot be a Resumable.
 
Upvote 0

Fernando Solá

Member
Licensed User
Longtime User
I know this is an old Thread, but just today I had the exact same issue with SettingWindowSizeLimits. So I'm posting here in case someone else needs it.

To solve the issue: Set the limits using the actual window's height and width after it has been rendered for the first time. My guess is that any customized OS with different heading height or border widths will produce a different result if you try to set the limits by using constant values to compensate for the offset. With that in mind I bypassed the issue with something like this:

B4X:
Sub Class_Globals
    Private MyForm As Form
    Private FormSizeLimitsSet As Boolean
End Sub

Public Sub ShowForm()

    'Obviously your form already has to be initialized and ready to be displayed.
    MyForm.Show
    
    If Not(FormSizeLimitsSet) Then
        'In my case, I just need the form to be able to grow within a range defined by the 1.28 factor.
        MyForm.SetWindowSizeLimits(MyForm.WindowWidth, MyForm.WindowHeight, MyForm.WindowWidth * 1.28, MyForm.WindowHeight * 1.28)   
        FormSizeLimitsSet = True
    End If

End Sub
 
Upvote 0
Top