2

I want to fire an event when right clicking on a tab, not the contents displayed by the tab, but the tabs themselves.

So far, I have tried using the selected event for the tabcontrol:

$maintab.add_selected({do something here})

this only fires when left clicking on the tabs

I also tried all of these, they don't seem to respond to clicks anywhere within the tabcontrol or the tabpages

$maintab.add_mouseUP({do something here})
$maintab.add_mouseDown({do something here})
$maintab.add_click({do something here})
$maintab.add_selecting({do something here})

I have also tried capturing the mouseUP event for the tabpages that have been added to the tabcontrol:

$tabpage.add_mouseUp({do something here})

This only works when clicking on the contents area below the tab, not the tabs themselves.

Is this even possible?

1 Answers1

1

I think you're right with using the MouseUP event on the maintab control.

Below shows you how you can detect which of these tabs was clicked:

$maintab.Add_mouseUP({
    param($sender,$e)
    if ($e.Button -eq [System.Windows.Forms.MouseButtons]::Right) {
        # this part checks if on of the actual tabs is right-clicked
        for ($i = 0; $i -lt $this.TabCount; $i++) {
            if ($this.GetTabRect($i).Contains($e.Location)) {
                # do something here
                Write-Host "Right-click on tab $($this.TabPages[$i].Text)"
                break
            }
        }
    }
})
Theo
  • 57,719
  • 8
  • 24
  • 41
  • you know its really odd, I had a this line commented out in my program from previous testing $maintab.add_mouseUP({write-host object: $this.name event: $_.button}). technically all I did was un-comment it and it works now. I did do some updating and rolling back of VSC first, but I don't see how that would affect it! either way, thanks for pointing me in the right direction! – Philosophical Aug 10 '21 at 13:11