How to Add/Remove tabs to tab control in a dialog programmatically

Hi, I can't seem to find any way to change the number of tabs a tab control can handle at runtime.

If I know my tabs prior to entering the script, I can choose the tabs content (e.g. dialogs assigned to each tab) directly in the script editor.
But my use case requires creating new tabs at runtime and I can't find how to do that.

Anyone has already faced this use case and has a solution ?

Thanks in advance.

There isn't a way at the moment.

An alternative (depending on what you want to change on each tab/page) would be using a list control instead of a tab, similar to the list on the left of Preferences.

1 Like

Thanks Leo for the quick answer.
Do you mean using the list as the "trigger" for the change and then rebuild the rest of the dialog dynamically ?
I think this could work indeed. Might have to play with redraw to avoid flickering, but this sounds like a good idea.

Could be worth adding this ability at some point to the tab object (recycling the AddItem method ??). But I understand this is far from being top of the list. I'll manage something.

Thanks again for the idea and the usual reactivity.

Yeah, although how well that would work may depend on what you need to change, and whether you need the controls to all be different on different pages, or just the data within them.

What I want is a bunch of buttons displaying images which paths are loaded from a file. All buttons are the same size and arranged the same way on each page. Number of images (hence number of "pages") are unknown at design stage.
So, that should work.

It's mostly working :slight_smile:
The concept is OK, but I couldn't get rid of a small flickering.

As you'll see, when I change the page, it goes through every button (3 columns of 11 buttons each) to do button.image = DOpus.LoadImage(pathToPng);
PNGs are small (less than 3kB each) and are stored on a fast SSD and absolutely no logging (neither console or file) occurs during the process.

I tried setting redraw to false on the tab control before the updates, then back to true after. It does not seem to change anything.
I also tried to loop through the buttons to do the same, but in that case, it's worse because ... the updates are not showing until mouse over for the button remaining active (in the example, on the second page, since only 1 remaining button needs to be shown, the other ones are blanked by button.image = ""; then button.enabled = false;). Disabled button do not get updated until I go back to page 1 (which redraws and re-enables all the buttons).

In the end, it pretty much solves my use-case, i'll live with the small flickering I guess :slight_smile:

EDIT: I tried pre-loading all the PNGs in a vector to avoid file read and potential time in transformation into image object : no discernible change.

Looks great here. Maybe the video didn't capture the flicker?

Flickering may not be the best term.
It's just we can (quickly) see every button refresh its image content one after another. I would have preferred everything to appear at once (hence trying to disable redraw on the "container" before change and re-enable it after).

More globally, I found that one type of control is missing (at least for me) sometimes : some kind of container that has auto-adding (or through properties) scrollbars when it gets bigger than its display size. Something like the BorderLayoutPanel or the FlowLayoutPanel in Windows.Forms.
It would have been useful here, but can also be used when you want to display text that you don't know the size at design stage.
That's probably not easy to implement in the current system as it would require to add docking or review/change the way the resize property works on current controls.

Anyway, for my use case here, the problem is solved. I'll go with that. Thanks Leo.

We've added a way to remove (and add back) tabs in 13.9.4.

1 Like