Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I implement a segmented Text box in c# that enforces user to enter values in specific format?

Tags:

c#

winforms

I need to implement a text box in windows forms where users must follow the constraint of the format of the values. For example, I want to force them to enter numbers in format: 00-000-0-0000, and I want the dashes to be present in the text box. I thought these are called segmented or formatted text input, but found nothing in google about it. Any sort of hint is appreciated.

like image 472
Thunderstruck Avatar asked Dec 06 '25 03:12

Thunderstruck


1 Answers

You're looking for MaskedTextBox which is exactly designed for such cases, you can find more info about it in MSDN

For your sample you just need to set the Mask property of MaskedTextBox to the format you provided:

maskedTextBox1.Mask = "00-000-0-0000";
like image 83
VahidNaderi Avatar answered Dec 08 '25 06:12

VahidNaderi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!