PowerShell winforms Tab selected index changed event

I have designed the GUI using WinForms in PowerShell as follows

Add-Type -Assembly 'System.Windows.Forms'

$form = New-Object Windows.Forms.Form

$TabControl = New-Object System.Windows.Forms.TabControl

$tabPage1 = New-Object System.Windows.Forms.TabPage
$tabPage1.Name = "Tab1"
$tabPage1.Text = "Tab1"
$tabPage1.Width = 500
$tabPage1.Height = 500

$tabPage2 = New-Object System.Windows.Forms.TabPage
$tabPage2.Name = "Tab2"
$tabPage2.Text = "Tab2"
$tabPage2.Width = 500
$tabPage2.Height = 500


$TabControl.TabPages.Add($tabPage1)
$TabControl.TabPages.Add($tabPage2) 

$TabControl.SelectedIndexChanged($TabControl_SelectedIndexChanged)

$TabControl_SelectedIndexChanged
{
    ({$selectedTab = $TabControl.SelectedTab;

    [System.Windows.Forms.MessageBox]::Show($selectedTab)})
}
$form.Controls.Add($TabControl)

I would like to handle the selectedindex changed event but I couldn't, I got the following error with the above code

Method invocation failed because [System.Windows.Forms.TabControl] does not contain a method named 'SelectedIndexChanged'. so can some one help me


Figured it out this is how I need to add the event

$TabControl.Add_SelectedIndexChanged({
    $selectedTab = $TabControl.SelectedTab
    [System.Windows.Forms.MessageBox]::Show($selectedTab.TabIndex)
})

instead of this

TabControl.SelectedIndexChanged($TabControl_SelectedIndexChanged)

$TabControl_SelectedIndexChanged
{
    ({$selectedTab = $TabControl.SelectedTab;

    [System.Windows.Forms.MessageBox]::Show($selectedTab)})
}