How can I embed a form in a Panel?
Posted
#1
(In Topic #1376)
Regular

I 'm a novice user of Gambas3 (version 3.19.5 on Linux Mint 21.3 and 22.0 -different computers- / installed Gambas3 the right way on both
I coded thus (with Form1 already designed) :
…but my Form1 seems hovering over the panel (and at different starting coordinates) and not inside it. Also, when I insert the "Form1.Parent = FMain.Panel1" directive in the Public Sub Menu1_Click() subroutine, the program execution stops with a "read-only" error on Form1.Parent.
Please note that I started the project as a graphical application, and checked the Project / Properties / Components as displayed on the attachment.
So:
- What did I do wrong?
- And why do I need a double press on the Menu1 area, to get a result (even erroneous)?
Thank you!
Posted
Regular

mandarin said
This is wrong in so may ways!
I presume that is the code for FMain?
Code (gambas)
- Form1.Parent = FMain.Panel1 <-- Form1 has not been instantiated. Why this doesn't raise a fatal error I cant even guess.
- Form1.Show()
Try this but first try to understand it from the above comments.
In FMain code:
As I have said many times before:
Read every word in the help, every word.
hth
thatbruce
Posted
Regular

I tried this scheme and it works fine (still necessary to click twice on Menu1, though) :
(On my previous try, Form1 sat correctly on (0, 0); but the dimensions of Panel1 were slightly bigger, due to my fault.)
Posted
Guru

There are 2 ways to embed a Form into Container…
Method 1
As an instance (will be like a copy of FMain and you can add as many as you want)
(Like other Bruce says)
Method 2 , Directly add FMain
Code (gambas)
- FMain.Load(Panel1)
- FMain.Show
The second method using Form.Load can only work with Forms. The first method using New cn be used to embed any object/control into any container.
And like the other Bruce says ,, read the wiki more. then read it some more
Posted
Guru

mandarin said
Thanks a lot! You saved me a couple of months of searching through the Gambas3 documentation!![]()
I tried this scheme and it works fine (still necessary to click twice on Menu1, though) :
(On my previous try, Form1 sat correctly on (0, 0); but the dimensions of Panel1 were slightly bigger, due to my fault.)
You are creating and adding Form1 twice there.
you should only create it once then use the Visible property to show or hide it..
Posted
Guru

mandarin said
Thanks a lot! You saved me a couple of months of searching through the Gambas3 documentation!![]()
I think you mean a couple of "minutes"
It's not that much of a maze.
Pages of interest…
/comp/gb.qt4 - Gambas Documentation
/comp/gb.form - Gambas Documentation
/lang - Gambas Documentation
/cat - Gambas Documentation
/howto - Gambas Documentation
Also check out the Application repository /app - Gambas Documentation
And the Farm (select farm from gambas welcome screen)
Examining other peoples code can be a great learning tool
Posted
Regular

Gambas3 is indeed a wonderful tool.
1 guest and 0 members have just viewed this.



