Page 1 of 1

Loop cycle through tabcontrol tabs

Posted: Mon Feb 18, 2019 2:55 pm
by thatsameer
Hi,

I have managed to successfully add new tabs to a form for each URL listed in a text file.

This is what it looks like:
cycleloop.PNG
cycleloop.PNG (15.41 KiB) Viewed 1063 times
I have added button1 as what I would like is for the tabs to cycle through in a loop, staying on each tab for lets say 5 seconds.

I have tried this:

$button1_Click = {
while (1 -eq 1)
{
$tabcontrol1.SelectedIndex++
UpdateNavButtons
Start-Sleep -s 5
$i++
}
}

The tabs cycle through but the form becomes inoperable and basically "freezes" the form. Also once it has reached the last tab it will not go further as it hits a virtual 'wall'...

Any ideas at all how to have the tabcontrol's tabs cycle through displaying each tab for X time in a continuous loop.

After this my project for this form will be complete so really would be helpful. thanks

Re: Loop cycle through tabcontrol tabs

Posted: Mon Feb 18, 2019 5:04 pm
by jvierra
Your code runs in an infinite loop. Here is the correct way to prevent infinite loops. Use a deterministic loop.

Code: Select all

$button1_Click={
    for ($i = 0; $i -lt $tabControl1.TabCount;$i++) {
        $tabcontrol1.SelectedIndex = $i
        Write-Host $tabcontrol1.SelectedTab.Name
        UpdateNavButtons
        Start-Sleep -Seconds 5
    }
    Write-Host finished
}

Re: Loop cycle through tabcontrol tabs

Posted: Tue Feb 19, 2019 3:29 am
by thatsameer
Thanks for this.

It works in terms of it cycles through the tabs however whilst cycling, the content of the tabs do not display as it seems while the process is running it locks up the form until its over...

I hope this makes sense? Please try recreating to see issue i am having if not clear.


many thanks

Re: Loop cycle through tabcontrol tabs

Posted: Tue Feb 19, 2019 5:40 am
by jvierra
I have no idea what you are trying to do. You asked about the tabs freezing. The code I posted does not cause the tabs to freeze.

Re: Loop cycle through tabcontrol tabs

Posted: Tue Feb 19, 2019 7:16 am
by thatsameer
The code cycles through the tabs successfully. But the tab contents do not display, and the GUI is unclickable while the loop is running. Only once the tab have completed it's cycle does it show the page it finished on.

I would like to see each tab and tab contents one by one in a loop

Re: Loop cycle through tabcontrol tabs

Posted: Tue Feb 19, 2019 8:01 am
by jvierra
Yes. That is how forms work. Perhaps you need to rethink your design.

Loading a browser is a heavy lift. Loading a bunch of browsers is going to lock up the form until all of the loading is done,

Re: Loop cycle through tabcontrol tabs

Posted: Tue Feb 19, 2019 9:38 am
by jvierra
Demo of loading multiple tabs:

Re: Loop cycle through tabcontrol tabs

Posted: Thu Feb 21, 2019 4:23 am
by jvierra
Here is an even better way to generate tab pages with browser controls.