I'm missing something obvious with Tab Controls

RacingDog

Active Member
Licensed User
OK, I did the basics, added the library and created a Tab Control.

In the code I have

Tabs.New1 ( "TicketPrices", 0, 0, TicketPrices.Width, TicketPrices.Height ) ' TicketPrices being the form
Tabs.AddTabPage ( "Prices" )
Tabs.AddTabPage ( "Sales" )
Tabs.AddTabPage ( "Till" )
Tabs.AddControl ( "PricesPanel", 0, 0, 0 )
Tabs.AddControl ( "SalesPanel", 1, 0, 0 )
Tabs.AddControl ( "TillPanel", 2, 0, 0 )
Tabs.SelectedIndex = 0

The panels are the same size.

I also tried having a sub

Sub Tabs_SelectionChanged
Select Tabs.SelectedIndex
Case 0
PricesPanel.BringToFront
Case 1
SalesPanel.BringToFront
Case 2
TillPanel.BringToFront
Case Else
End Select
End Sub

But all I ever see is the controls located on the first panel, PricesPanel, regardless of which Tab I click.

Is it relevant that PricesPanel, itself has 3 panels containing the various other controls? I have all the controls set to have their panel's as parent. The compiler objects if I low level edit the file to try make the subsidiary panels have the main panels as parents, so they have the form as parent instead. That may be the problem.

I've just got a table on each of the other panels, SalesPanel and TillPanel just to have some thing to see as I haven't got as far as doing those for real. But they never appear.

Is there a problem with making the three main panels the full size of the form?

OK, stop laughing, just tell me what I didn't do please. :sign0085:

Ta.
 
Hello.
I may be way off the mark.... I have tested the code above:

Select tab.SelectedIndex
Case 1
SalesPanel.BringToFront

.......brings to front only SalesPanel, without the controls on it.

I dont see another way but bringing to front each control on each panel.
 

Attachments

  • ControlsEx.zip
    8.9 KB · Views: 191

agraham

Expert
Licensed User
Longtime User
@nicolasWhite - you need to add a panel to each tab.

@RacingDog - unless you post the code we won't be able to help. I suspect that you have a parenting problem with your controls. This small program works fine for me.
 

Attachments

  • tabs.sbp
    1.1 KB · Views: 189

RacingDog

Active Member
Licensed User
Yeah, that's why I asked about parenting. It's not easy to see unless you dive off into notepad. Had a quick look that way and didn't spot anything. Is there an easier way? Perhaps there should be an easier way.

I just reduced the main panel sizes to allow for the height of the tab control. This is how I had it originally, but I just wanted to see if there was a combination efect with the other things I'd tried. It made no difference.

Sorry about the lack of indentation. It was there when I created the post, but the tabs got taken out when posted and as it was well after midnight, I just went to bed instead of editting it again.

Thanks to all above.

Here is the program so far with all the distracting details.
 

Attachments

  • CWR Tickets.sbp
    7 KB · Views: 211

agraham

Expert
Licensed User
Longtime User
The problem is that you are trying to place Panels on Panels. As far as I can see Panels, unlike other controls, are always created with the Form on which they are designed as the parent. You do not seem to be able to change the parent in the designer as Tools -> Change Parent does not work for Panels. Although the code emitted in the designer section of the sbp file appears to place the Panel on another Panel this does not happen at runtime.

I notice that the help for AddPanel states Adds a Panel to a Form at runtime whereas AddButton states Adds a Button to a Form or to a Panel at runtime. So it appears that the panel parameters of the AddPanel lines in the designer section of the source code that specify another panel as the parent are ignored.

I assume this limitation is intended for some reason but the behaviour and emitted code is confusing. Erel?
 
I should say someone indeed is missing obvious....
Panel1,Panel2,Panel3 dont belong to SalesPanel but to the form.
In the disignner try moving SalesPanel with a mouse....the abovementioned panels remain where they are
 

corwin42

Expert
Licensed User
Longtime User
I have reported this some time ago here: http://www.b4x.com/forum/bug-reports/4620-panel-can-not-child-another-panel-designer.html

You can only change the Parent of a Panel with formlib.ChangeParent. I also needed this for a tab control. I don't know why this is a restriction in B4PPC designer.

Another thing you have to know with the tabcontrol is that the tabcontrol itself consists of a Panel and a TabControl Control as child. So if you want to dock the panel to its parent container you can't set the dock property of the tabcontrol but you have to get the parent object and set the dock property for the parent panel like this (dobj is a door.library object):

B4X:
  dobj.FromControl(TabMain.ControlRef)
  dobj.Value = dobj.GetProperty("Parent")
  dobj.SetProperty("Dock", c.DSFill)
 

klaus

Expert
Licensed User
Longtime User
You can also use standard panels on the form and select the panel belonging to a tab with the Visible parameter.
If you need complemetary panels on the tab's main panels you must use ChangeParent from the FormLib.

Attached an example.

Best regards.
 

Attachments

  • TabTest.sbp
    2.2 KB · Views: 172

RacingDog

Active Member
Licensed User
Dang, I thought it might be something like that. That is a shame. This all started out as a single form which people are used to. But transporting it on to tab one of three is now going to look different. Fortunately I was using close grey colours so maybe no one will notice if they disappear in certain places.

I've got side tracked into something else today, but I'll give it another go very soon. So thanks for all that. I'll try to remember to put in one more post to say it works, when it does!

For the curious, this is used, mainly by me it has to be said, on a preserved railway I volunteer on, which is a charity.
 

RacingDog

Active Member
Licensed User
I should say someone indeed is missing obvious....
Panel1,Panel2,Panel3 dont belong to SalesPanel but to the form.
In the disignner try moving SalesPanel with a mouse....the abovementioned panels remain where they are

Well, yes perhaps if one uses this environment regularly, but given other environments don't have this restriction that makes it less obvious. I've always thought restrictions should be clearly stated. Still, we know now.
 

RacingDog

Active Member
Licensed User
Well that was tedious, changing the control parents before deleting the secondary panels meant I had to realign everything, and for some strange reason it wasn't just adding constants to the previous top and left values. Never mind, it works on the PC now. No doubt I'll have to re-jiggle on the device, but that won't be for a while yet.

So thanks again folks.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…