B4J Question How to add a new form (Newbie)

Discussion in 'B4J Questions' started by tdocs2, Aug 2, 2015.

  1. tdocs2

    tdocs2 Well-Known Member Licensed User

    Greetings.

    I am using the Open Designer...

    How to add a new form to a project (B4A under Project Add New Module >Acitivity)?
    How to start or load the new form from Main?
    Are there examples of multiform projects?

    I have searched, but I do not seem to get the answer - I saw a modal form example using a Class module...

    For example, simple Financial app with a Main Form, Customer Form, Transaction Form, Reporting Form....

    Thank you.

    Sandy (Newbie B4J)
     
    Last edited: Aug 2, 2015
  2. Roycefer

    Roycefer Well-Known Member Licensed User

    Just create a new Form variable, initialize it, load a layout and then show it:
    Code:
    Dim newForm As Form
    newForm.Initialize(
    "newForm"100,100)
    newForm.RootPane.LoadLayout(
    "newFormLayout")
    newForm.Show
    If you take a look at the template code in a UI app, all those steps are performed with MainForm, with the exception of initialization, in Process_Globals() and AppStart().

    You can create the newFormLayout with the Designer. The above code can appear in your Main module; no need to create a new module for it as in B4A and Activities. You can, if you want, make a Form a member of a class (click Project>Add New Module>Class Module), but that isn't necessary. I would recommend putting newForm's event subs and MainForm's event subs in separate regions for purposes of code readability:

    Code:
    #Region MainFormEvents
    'MainForm events
    #End Region

    #Region newFormEvents
    'newForm events
    #End Region
    but again, it's not necessary.
     
    kazem forghani, tdocs2 and LucaMs like this.
  3. LucaMs

    LucaMs Expert Licensed User

    Use Regions! ;).


    Just two things:

    1) you can set the owner of new forms (NewForm.SetOwner) and the new form is shown above the Main form.
    2) you can declare the new form as Public and I don't know if you can have some advantages
     
    tdocs2 likes this.
  4. tdocs2

    tdocs2 Well-Known Member Licensed User

    Thank you, Roycefer.

    Thank you, Luca.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice