How to navigate to a new Form

Post your Gambas programming questions here.
Post Reply
maldus
Posts: 3
Joined: Tuesday 22nd October 2019 6:12am

How to navigate to a new Form

Post 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?
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: How to navigate to a new Form

Post 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
maldus
Posts: 3
Joined: Tuesday 22nd October 2019 6:12am

Re: How to navigate to a new Form

Post 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.
Attachments
MultiForm.tar.gz
(12.22 KiB) Downloaded 383 times
User avatar
gbWilly
Posts: 68
Joined: Friday 23rd September 2016 11:41am
Location: Netherlands
Contact:

Re: How to navigate to a new Form

Post 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..
gbWilly
- Dutch translation for Gambas3
- Gambas wiki content contributer


... there is always a Catch if things go wrong!
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: How to navigate to a new Form

Post 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
maldus
Posts: 3
Joined: Tuesday 22nd October 2019 6:12am

Re: How to navigate to a new Form

Post 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?
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: How to navigate to a new Form

Post 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.
Post Reply