disable a key press in a textbox
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.
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.
disable a key press in a textbox
I want to disable the use of the period key within a textbox. How would I go about doing that?
Re: disable a key press in a textbox
To filter keys on input add the following event:
This behavior is not clearly documented except in the MSDN documents and examples.
Code: Select all
$textbox1_KeyPress=[System.Windows.Forms.KeyPressEventHandler]{
#Event Argument: $_ = [System.Windows.Forms.KeyPressEventArgs]
if($_.KeyChar -eq '.'){
Write-Host 'Cancel keystroke'
$_.Handled = $true
}
}
- mxtrinidad
- Posts: 399
- Last visit: Tue May 16, 2023 6:52 am
Re: disable a key press in a textbox
As the code above was provided, PowerShell Studio need first the register the event before adding the above code inside the event. (see image below)