Use textbox to open form make sound

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.
Locked
User avatar
CRONSSE
Posts: 3
Joined: Tue Nov 07, 2017 12:08 am

Use textbox to open form make sound

Post by CRONSSE » Fri Dec 28, 2018 3:50 am

I have a program that runs a user search based on a textbox, when the user presses the enter key a new form is open and show all users find based on the textbox content.

Here is an example of my code :
$UserBadge_KeyDown = [System.Windows.Forms.KeyEventHandler]{
if ($_.KeyCode -eq 'Enter')
{
$_.Handled = $true
$_.SuppressKeyPress = $true
Show-FindUser_psf -User $UserBadge.text
}
}

I can't use the AcceptButton property on the MainForm neither than the Multiline on my textbox property and so it makes the windows "ding" sound when pressed.

Is there an other way to stop this sound ?

User avatar
jvierra
Posts: 13681
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Use textbox to open form make sound

Post by jvierra » Fri Dec 28, 2018 4:59 am

Please post a simple sample PSF of your issue.

User avatar
jvierra
Posts: 13681
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Use textbox to open form make sound

Post by jvierra » Fri Dec 28, 2018 5:30 am

I should also note that you cannot use multiline and trap the return key or use the "AcceptButton" and trap the return key.

User avatar
CRONSSE
Posts: 3
Joined: Tue Nov 07, 2017 12:08 am

Re: Use textbox to open form make sound

Post by CRONSSE » Fri Dec 28, 2018 5:42 am

Thanks for your quick reply.
I made an exemple for demonstration.
In fact my script is more complex because I have an Active Directory search
You can find Screenshots of my interface in .zip file.
Attachments
test.zip
(74.84 KiB) Downloaded 25 times

User avatar
jvierra
Posts: 13681
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Use textbox to open form make sound

Post by jvierra » Fri Dec 28, 2018 6:00 am

I need a PSF and not a picture.

User avatar
jvierra
Posts: 13681
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Use textbox to open form make sound

Post by jvierra » Fri Dec 28, 2018 6:01 am

Sorry. I now see the folder in the zip.

User avatar
jvierra
Posts: 13681
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Use textbox to open form make sound

Post by jvierra » Fri Dec 28, 2018 6:19 am

Whenever you repurpose the return key then any change of focus will cause a bell sound. This is an unfortunate side effect of a dialog. I suggest using a button to open the subform and not using the enter key.

User avatar
CRONSSE
Posts: 3
Joined: Tue Nov 07, 2017 12:08 am

Re: Use textbox to open form make sound

Post by CRONSSE » Fri Dec 28, 2018 6:51 am

That's what I was afraid to hear.
Thanks anyway for your time and your help.

Locked