B4J Question Returning to the main form

khwarizmi

Active Member
Licensed User
Longtime User
Hi all

How can I return to the main form from another form after closing by: MainForm.Close?

thanks
 
Solution
As the error says, you can't call Form.SetFormStyle after the form has already been shown.
I'd suggest you watch the Code Modules and Classes video tutorial:
In particular, from around the 18 minute mark, it explains about forms in class modules and code modules.

In code modules you need to use something like:
B4X:
Public Sub Show
    If HomePg.IsInitialized=False Then
        HomePg.Initialize("HomePg", 600, 600)
        HomePg.RootPane.LoadLayout("HomePgLayout")
        HomePg.SetFormStyle("TRANSPARENT")
        :
        :
        etc
    End If
    :
    :
End Sub

Chris2

Active Member
Licensed User
As the error says, you can't call Form.SetFormStyle after the form has already been shown.
I'd suggest you watch the Code Modules and Classes video tutorial:
In particular, from around the 18 minute mark, it explains about forms in class modules and code modules.

In code modules you need to use something like:
B4X:
Public Sub Show
    If HomePg.IsInitialized=False Then
        HomePg.Initialize("HomePg", 600, 600)
        HomePg.RootPane.LoadLayout("HomePgLayout")
        HomePg.SetFormStyle("TRANSPARENT")
        :
        :
        etc
    End If
    :
    :
End Sub
 
Upvote 1
Solution

DonManfred

Expert
Licensed User
Longtime User
Probably with
B4X:
MainForm.Show
 
Upvote 0

khwarizmi

Active Member
Licensed User
Longtime User
MainForm contains the sub:
B4X:
Sub AppStart (Form1 As Form, Args() As String)

I thought to call it but I didn't know any Args should I put.
 
Last edited:
Upvote 0

Chris2

Active Member
Licensed User
I think you're confusing MainForm with the Main code module of the app.
The Main code module contains AppStart which is called when the app starts up. MainForm is just the main/starting form of your UI program.
 
Upvote 0

khwarizmi

Active Member
Licensed User
Longtime User
Thanks Chris2
I got confused because all the code modules in my program contain the show event, which initialize the associated form and loads the layout in its root pane. Except for the main form, which initialize with:

B4X:
Sub AppStart (Form1 As Form, Args() As String)

I noticed that any variable of type form has a shoe property.
Then I set the variable MainForm to public and the code:

B4X:
MainForm.Show

works from anywhere.
 
Upvote 0

khwarizmi

Active Member
Licensed User
Longtime User
Now a new problem appeared when returning again to the second form (HomePg), which contains:

B4X:
HomePg.SetFormStyle("TRANSPARENT")

Error message:
B4X:
(IllegalStateException) java.lang.IllegalStateException: Cannot set style once stage has been set visible
 
Upvote 0

khwarizmi

Active Member
Licensed User
Longtime User
Thanks, now the error message is gone by inserting the code:

B4X:
HomePg.SetFormStyle("TRANSPARENT")

inside the If statment, to be executed only when the form is not initialized.
 
Upvote 0
Top