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.
This topic is 5 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
CRONSSE
Posts: 3
Last visit: Thu Dec 21, 2023 1:16 am

Use textbox to open form make sound

Post by CRONSSE »

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 ?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Use textbox to open form make sound

Post by jvierra »

Please post a simple sample PSF of your issue.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Use textbox to open form make sound

Post by jvierra »

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
Last visit: Thu Dec 21, 2023 1:16 am

Re: Use textbox to open form make sound

Post by CRONSSE »

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 92 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Use textbox to open form make sound

Post by jvierra »

I need a PSF and not a picture.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Use textbox to open form make sound

Post by jvierra »

Sorry. I now see the folder in the zip.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Use textbox to open form make sound

Post by jvierra »

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
Last visit: Thu Dec 21, 2023 1:16 am

Re: Use textbox to open form make sound

Post by CRONSSE »

That's what I was afraid to hear.
Thanks anyway for your time and your help.
This topic is 5 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked