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 2 years and 8 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.
PowerShell Studio 2021 Version 5.8.190
Windows 10 x64 Build 18363.1679
I am attempting to validate the key presses in a masked textbox to fit the characters for a MAC address. I only want to allow the characters A-F and 0-9 to be typed in the field. Here is the code for the KeyPress event.
This code works perfectly fine on a standard text box but it does not seem to work on a MaskedTextBox. I copy and pasted it directly to another TextBox event handler and it worked as expected. I have used the debugger to verify that the event is running on a keypress, the regex is working as expected, and that the Handled property is getting set to $true but unmatched characters are still entered into the MaskedTextBox. Any ideas what may be causing this?
This doesn't work either. Again, I've debugged step by step to make sure that the logic is working as intended and that the Handled property is being set to $true. It just seems that $_.Handled -eq $true is not keeping to key press from showing up in the maskedtextbox the way that it would in a normal textbox
loganstanford wrote: ↑Thu Aug 12, 2021 10:18 am
This doesn't work either. Again, I've debugged step by step to make sure that the logic is working as intended and that the Handled property is being set to $true. It just seems that $_.Handled -eq $true is not keeping to key press from showing up in the maskedtextbox the way that it would in a normal textbox
It works without issue when I use the code posted above. Perhaps you should start by building a new form and just try that simple code.
Remember the match is positive for the template so the characters in the template will be excepted and all otheres will be rejected.
Also the Net Framework may need updating although I have never seen such a simple issue like this be dependent on Net issues.
This topic is 2 years and 8 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.