MaskedTextBox validation if box not used

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 7 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
harringg
Posts: 18
Last visit: Mon Oct 30, 2023 11:13 am

MaskedTextBox validation if box not used

Post by harringg »

I've got a successful validation on a text box, but in the event the user doesn't have the information, and they click inside the box, the cursor is "locked" in the box until they enter text.

Scenario, if a user has a PersonGUID from an external system, I want them to enter in the box, and I want to make sure they enter it in the correct format.
If they don't have that information, and are tabbing through the form, I want them to be able to proceed to the next box.

Is there an event handler that I need to add to my form to make this happen?

Or by it's very nature, is data required to be entered if the validation event is applied?

Code: Select all

$maskedtextboxPersonGUID_Validating = [System.ComponentModel.CancelEventHandler]{
	#Event Argument: $_ = [System.ComponentModel.CancelEventArgs]
	if (-not $maskedtextboxPersonGUID.MaskFull)
	{
		$_.Cancel = $true
		$errorprovider1.SetError($maskedtextboxPersonGUID, "Numbers and Letters (8-4-4-4-12)");
	} #end if (-not $maskedtextboxPersonGUID.MaskFull)
} #end $maskedtextboxPersonGUID_Validating
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: MaskedTextBox validation if box not used

Post by jvierra »

1. Don't validate the box, validate the form when submitted.
2. A masked textbox is not usually validated in the event. Its purpose is to control the characters being typed by masking the whole input.

Use your search engine to get examples on many ways to handle using the MaskedTextbox.
This topic is 2 years and 7 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