B4J Question B4J: questions about opening different forms in the same app

vmag

Active Member
- How can I open the second form from the first form and close the first form ?
- How do I close the second form and open the first one again ?
- Is it possible not to display the form x close button ?
- How do I load another form layer in RootPane so that the previous one is not displayed?
- How to catch the Form_Close event ?
 

Daestrum

Expert
Licensed User
Longtime User
This example covers most of what you ask - except rootpane - but that can be done when on other form
(Note example uses cssutils library)
B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Dim b,b1 As Button
    Dim myNewForm As Form
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1

    ' initialize the new form
    myNewForm.Initialize("mynewform",200,200)
    myNewForm.Title = "My New Form"
    myNewForm.SetFormStyle("UNDECORATED") ' UTILITY will give close button so u can trap that

    ' add outline to mynewform so u can see it
    CSSUtils.SetBorder(myNewForm.RootPane,3.0,fx.Colors.red,2.0)

    ' put button on mainform
    b.Initialize("newform")
    b.Text = "show other form"
   
    ' put button on other form
    b1.Initialize("newform")
    b1.Text = "show other form"
   
    MainForm.RootPane.AddNode(b,10,10,100,20)
    myNewForm.RootPane.AddNode(b1,10,10,100,20)
    ' show mainform
    MainForm.Show
End Sub

Sub newform_Click
    If MainForm.Showing Then
        ' show new form
        myNewForm.Show
        ' close mainform
        MainForm.Close
    Else
        ' show mainform
        MainForm.Show
        ' close new form
        myNewForm.close
    End If
End Sub

' how to trap the close event
Sub myNewForm_CloseRequest (EventData As Event)
    Log("Naughty you cannot use the X to close")
    EventData.Consume
End Sub
 
Last edited:
Upvote 0

vmag

Active Member
I also can't load different forms in the Pane one at a time, they overlap and all the controls are mixed in a heap. Is it possible to clear the contents of the Pane before uploading a new form to it? The algorithm is similar to this: 1. the main form is Loaded with the Main buttons and Pane. 2. when you click on any button, the Pane is cleared and the corresponding form is loaded into it (Form1, Form2,...)
 

Attachments

  • pane.jpg
    pane.jpg
    89.8 KB · Views: 156
Upvote 0

vmag

Active Member
Thank you, this is what you need! I am more and more convinced that B4 is a good development tool, and the only problem is the lack of sufficient knowledge.
 
Upvote 0
Top