Page 1 of 1

How to navigate to a new Form

Posted: Tuesday 22nd October 2019 6:14am
by maldus
I find myself having to deal with some delightful legacy software written in Gambas3. I have to extend the functionality of a small GUI application with a new control page.

Naturally, as for similar GUI libraries I've worked with (web, Android development, flutter, ...) I came looking for a way to navigate between different pages. It is almost implied as possible by the organization in .form files.

Unfortunately, I couldn't find a way to achieve this. Given multiple different Form objects, how can I swap the currently viewed window between them?

Re: How to navigate to a new Form

Posted: Tuesday 22nd October 2019 12:04pm
by cogier
Welcome to the forum :D
Given multiple different Form objects, how can I swap the currently viewed window between them?
I am not sure I fully understand the question but here is a small program switching between 5 TextAreas. If it's not what you want then let me know.
Views.tar.gz
(12.98 KiB) Downloaded 360 times

Re: How to navigate to a new Form

Posted: Tuesday 22nd October 2019 3:12pm
by maldus
Welcome to the forum
Thank you!
I am not sure I fully understand the question but here is a small program switching between 5 TextAreas. If it's not what you want then let me know.
It's a start. I want to have separate "Views" of my application with different purposes (say, a normal usage view + a settings/options view).
In your example you keep all objects into the same Form, hiding all but one of them at any given time. This would achieve my objective, but I was wondering if there was a better way to do it.

In the project I have attached I have two separate forms; I would like to "navigate" (if it makes sense in a Gambas3 context) from the first to the second and return by clicking the buttons.

If this is not possible then my next question would be what is the point of having multiple separate class source files in the same project.

Re: How to navigate to a new Form

Posted: Tuesday 22nd October 2019 3:30pm
by gbWilly
Hi maldus,

I guess this is what you want to do:

Code for FMain:
Public Sub Button1_Click()

  FSecond.Show
  Me.Hide

End
Code for FSecond:
Public Sub Button1_Click()

  FMain.Show
  Me.Hide

End
You can also use Me.Close on the forms if you like. In code above they stay opened but hidden.
If the idea here is to make some sort of wizard have a look at http://gambaswiki.org/wiki/comp/gb.form/wizard

Enjoy..

Re: How to navigate to a new Form

Posted: Tuesday 22nd October 2019 3:40pm
by cogier
OK, I think I get it now. Have a look at the attached.
MultiForm.tar.gz
(34.4 KiB) Downloaded 351 times
EDIT. It seems gbWilly had the same idea and beat me to it! :D

Re: How to navigate to a new Form

Posted: Wednesday 23rd October 2019 7:04am
by maldus
Yes, this was exactly what I was looking for! Thank you for the assistance.

Just one last question. In the example provided by @cogier the window changes position when switching from the first to the second Form. I couldn't find the reason behind this behavior in the code, can someone clarify it for me?

Re: How to navigate to a new Form

Posted: Wednesday 23rd October 2019 7:25am
by cogier
Just one last question. In the example provided by @cogier the window changes position when switching from the first to the second Form. I couldn't find the reason behind this behavior in the code, can someone clarify it for me?
'Me' refers to the Form so to position the Form you use 'Me. X' for the horizontal position and 'Me. Y' for the vertical position. As the Form is automatically centered all I had to do was change the 'X' position which is in the code I posted.