Change Tab Focus by Mouse Double Click Event

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.
ClipperXTP
Posts: 27
Joined: Tue Apr 28, 2020 4:07 am

Change Tab Focus by Mouse Double Click Event

Post by ClipperXTP »

Hi

I have a project with two tab pages.
The first tab I use to query PCs. There is a textbox where the PC name is entered and a button my users click and PC info is returned.

The second tab I use to query user details.
On the User tab page, the user naturally has PCs that are assigned to them.
These are returned to a Datagridview when I query against the user.

I would like to be able to double click on one of the PC names in the datagridview on the User tab page, and with the mouse double click event, switch focus to the PC tabpage and populate the PC name textbox. I know how to populate the textbox with the line from the datagridview but is it possible to change focus as part of the mouse double click event?
thanks in advance

jvierra
Posts: 14452
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Change Tab Focus by Mouse Double Click Event

Post by jvierra »

Use the "Focus()" method of the control.

$textbox.Focus()

https://docs.microsoft.com/en-us/dotnet ... trol_Focus

ClipperXTP
Posts: 27
Joined: Tue Apr 28, 2020 4:07 am

Re: Change Tab Focus by Mouse Double Click Event

Post by ClipperXTP »

Hi - I have tried the following - I put a button on a different tab page as a test, clicking the button doesn't change the focus to the tab page where the text box is? What am I missing? Thanks

$button1_Click={
#TODO: Place custom script here
$textbox_computername.Focus()
}

jvierra
Posts: 14452
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Change Tab Focus by Mouse Double Click Event

Post by jvierra »

YOU are not using the double-click event in your code.

ClipperXTP
Posts: 27
Joined: Tue Apr 28, 2020 4:07 am

Re: Change Tab Focus by Mouse Double Click Event

Post by ClipperXTP »

No in this instance I am just trying to test the focus method. Should I expect my example above to work? Thanks

jvierra
Posts: 14452
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Change Tab Focus by Mouse Double Click Event

Post by jvierra »

No way to guess at what you are trying to do.

ClipperXTP
Posts: 27
Joined: Tue Apr 28, 2020 4:07 am

Re: Change Tab Focus by Mouse Double Click Event

Post by ClipperXTP »

Sorry, in this instance I want to test performing an action with a control in one page tab to see if it will change the focus to another page tab.

As a test I set the button1 click event on one tab page to change the focus to my text input box on the other tab page. Running the project and clicking the button had no effect. Would you expect the behavior I described?

$button1_Click={
#TODO: Place custom script here
$textbox_computername.Focus()
}

jvierra
Posts: 14452
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Change Tab Focus by Mouse Double Click Event

Post by jvierra »

Use "Select()"

"Focus" only works when a control is visible.

ClipperXTP
Posts: 27
Joined: Tue Apr 28, 2020 4:07 am

Re: Change Tab Focus by Mouse Double Click Event

Post by ClipperXTP »

Hi - I have changed to select - it still does not take me to the other tab?..

$button1_Click={
#TODO: Place custom script here
$textbox_computername.Select()
}

jvierra
Posts: 14452
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Change Tab Focus by Mouse Double Click Event

Post by jvierra »

No. Select just makes the control the current control on the tab it is on. You still need to select the tab you want to make it visible.

Locked