PS Gui, Tabcontrol how to confirm if tab is selected

This topic contains 1 reply, has 1 voice, and was last updated by Profile photo of cm it cm it 1 year, 5 months ago.

  • Author
    Posts
  • #32719
    Profile photo of cm it
    cm it
    Participant

    So i'm creating my first tool. It has 3 tabpages , each with its own tasks.
    Now, when the app gets loaded, all functions are loaded at once. (and so all tabs are loaded at once)
    It would like to make it so that all functions get loaded when the tab if selected or clicked on.

    so i have

    #Tab Control 
    $tabControl.DataBindings.DefaultDataSourceUpdateMode = 0
    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 75
    $System_Drawing_Point.Y = 85
    $tabControl.Location = $System_Drawing_Point
    $tabControl.Name = "tabControl"
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 300
    $System_Drawing_Size.Width = 575
    $tabControl.Size = $System_Drawing_Size
    $form1.Controls.Add($tabControl)
    

    and e.g.

    #SQLHealth Page
    $SQLHealthPage.DataBindings.DefaultDataSourceUpdateMode = 0
    $SQLHealthPage.UseVisualStyleBackColor = $True
    $SQLHealthPage.Name = "SQLHealthPage"
    $SQLHealthPage.Text = "SQL Health Check"
    $tabControl.Controls.Add($SQLHealthPage)
    
    #CPU Page
    $CPUPage.DataBindings.DefaultDataSourceUpdateMode = 0
    $CPUPage.UseVisualStyleBackColor = $True
    $CPUPage.Name = "CPU"
    $CPUPage.Text = "CPU"
    $tabControl.Controls.Add($CPUPage)
    

    i tried the following but that doesn't work.

    if ($TabControl.SelectedTab = $CPUPage)
    {
    	Write-Host "hello tab cpuPage"
    }
    
  • #32721
    Profile photo of cm it
    cm it
    Participant

    So i figured it out, what you need to do is create a handler and then add it to the object. so
    first you do :

    $handler_tabpage_SelectedIndexChanged = {
    	Write-Host $tabControl.SelectedTab.Name
    	Write-Host "you changed tabs"
    }
    

    and later on you add:

     
    $TabControl.add_SelectedIndexChanged($handler_tabpage_SelectedIndexChanged)
    

You must be logged in to reply to this topic.