Home > Software design >  How do I make a textbox that only accepts a type of data?
How do I make a textbox that only accepts a type of data?

Time:01-13

I'm making a form and would like to know how to make it accept only one type of date. (Ex: DD/MM/YYYY)

enter image description here

I tried to find something referring to #c but I only found the logic for numbers and not date formats

CodePudding user response:

you can use NuGet MaskedTextBox, and call like this:

maskedTextBox1.Masked = MaskedTextBox.MaskedTextBox.Mask.DateOnly;

Code and example: https://github.com/abbaye/Winform-MaskedTextBox

CodePudding user response:

What you are looking for is the DateTimePicker in the toolbox. This tool allows you to only insert types of DateTime. Then in your code you can change it to any format you would like with the Tostring method. look in this webpage to look into formating of DateTime: https://www.c-sharpcorner.com/blogs/date-and-time-format-in-c-sharp-programming1

  • Related