GUI - Tab Control tabs - Disable/Not clickable

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 6 years and 11 months 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
angelofstealth
Posts: 69
Last visit: Wed Sep 28, 2022 10:04 am

GUI - Tab Control tabs - Disable/Not clickable

Post by angelofstealth »

I'm trying to not make certain form control tabs not clickable on form load. List example below, wondering what i am missing, thanks

Example:

$tabcontrol1.Enabled = $false <-- will disable the whole tabcontrol

$tabpage2.Enabled = $false <-- disables the tabpage

Want to disable the $tabpage2 from not being clicked on to view the control.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: GUI - Tab Control tabs - Disable/Not clickable

Post by jvierra »

Disabling a tab only disables the controls within the tab.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: GUI - Tab Control tabs - Disable/Not clickable

Post by jvierra »

The following event will prevent selection of disabled tab pages:

  1. $tabcontrol1_Selecting=[System.Windows.Forms.TabControlCancelEventHandler]{
  2. #Event Argument: $_ = [System.Windows.Forms.TabControlCancelEventArgs]
  3.     if(-not $_.TabPage.Enabled){
  4.         $_.Cancel = $true
  5.     }
  6. }
User avatar
angelofstealth
Posts: 69
Last visit: Wed Sep 28, 2022 10:04 am

Re: GUI - Tab Control tabs - Disable/Not clickable

Post by angelofstealth »

This doesn't seem to work for me after a form load. I pasted this code after my form load and disabled the tabpages in the formload and they are still clickable.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: GUI - Tab Control tabs - Disable/Not clickable

Post by jvierra »

You have to connect the event to the control for it to b e called.
DevinL
Posts: 1098
Last visit: Tue Jun 06, 2017 9:15 am

Re: GUI - Tab Control tabs - Disable/Not clickable

Post by DevinL »

jvierra wrote:You have to connect the event to the control for it to b e called.
In case OP or anyone else isn't too sure how to do this, the easiest way would be to select the control you wish to add the event to, click on the Events button in the Properties panel, and double click on the event you wish to add:
New_Event.png
New_Event.png (27.64 KiB) Viewed 4216 times
DevinL
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: GUI - Tab Control tabs - Disable/Not clickable

Post by jvierra »

As a shortcut, right click the control and select "add events" or just select the control and hit "Crtl-E". Check the event you want to add and click "Create". You will be placed in the edit pane in the new event.

When selecting a composite control be sure you have selected the container control and not an element. With Tab the pages usually get selected so be sure to click on the tab control and not on a page.

I have found that learning the shortcuts can save a tremendous amount of time and errors. They also help us to avoid having to search a long properties or events list on the "Properties" pane.
This topic is 6 years and 11 months 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