Selected Tab Validation

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 11 years and 3 weeks old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
jimbobukii
Posts: 52
Last visit: Mon Dec 04, 2017 9:59 am

Selected Tab Validation

Post by jimbobukii »

Hi all

I was wondering if someone could help

I have a number of tabs in a tabcontrol if a specific tab is selected I want to perform an action. I am unsure of how to set this up

Example:

if
(tab1.selected = $true){
write-host 'Tab one selected'
}
if
(tab2.selected = $true){
write-host 'Tab two selected'
}

Thanks in advance
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Selected Tab Validation

Post by jvierra »

There is an event that is fired when the tab is selected.
Look at the events for the tab control.

The event is the 'Click' event and the tab is found by looking at:
$tabcontrol1.SelectedTab.Text
User avatar
jimbobukii
Posts: 52
Last visit: Mon Dec 04, 2017 9:59 am

Re: Selected Tab Validation

Post by jimbobukii »

jvierra wrote:There is an event that is fired when the tab is selected.
Look at the events for the tab control.

The event is the 'Click' event and the tab is found by looking at:
$tabcontrol1.SelectedTab.Text
I have had a look at this but am unable to find how to do this
Any chance you could send me a demo pff?

I have:
2 tabs
if tab two is clicked a message box will appear

sounds simple but got me stumped!!

Thanks in advance
User avatar
jimbobukii
Posts: 52
Last visit: Mon Dec 04, 2017 9:59 am

Re: Selected Tab Validation

Post by jimbobukii »

Worked it out :)

I was using
PowerShell Code
Double-click the code block to select all.
if($tabcontrol1.SelectedTab = $taberror){Write-Host 'error tab'}
instead of
PowerShell Code
Double-click the code block to select all.
if($tabcontrol1.SelectedTab -eq $taberror){Write-Host 'error tab'}
Thank you for your help
This topic is 11 years and 3 weeks old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked