C# MASKED TEXTBOX | C# DATETIME PICKER | 4X SPEED
Programming Guru
A MaskedTextBox control provides a validation mechanism for user input on a Form. For example, if you want a TextBox to accept a date in mm/dd/yyyy format, you can set masking in the MaskedTextBox.
In this article, I will discuss how to create a MaskedTextBox control in Windows Forms at design-time as well as run-time. After that, I will continue discussing various properties and methods available for the MaskedTextBox control.
Creating a MaskedTextBox
We can create a MaskedTextBox control using a Forms designer at design-time or using the MaskedTextBox class in code at run-time (also known as dynamically).
To create a MaskedTextBox control at design-time, you simply drag and drop a MaskedTextBox control from Toolbox to a Form in Visual Studio. After you drag and drop a MaskedTextBox on a Form, the MaskedTextBox looks like Figure 1. Once a MaskedTextBox is on the Form, you can move it around and resize it using mouse and set its properties and events.
MaskedTextBox Figure 1
Creating a MaskedTextBox control at run-time is merely a work of creating an instance of MaskedTextBox class, setting its properties and adding MaskedTextBox class to the Form controls.
The first step to create a dynamic MaskedTextBox is to create an instance of MaskedTextBox class. The following code snippet creates a MaskedTextBox control object.
MaskedTextBox dynamicMaskedTextBox = newMaskedTextBox();
In the next step, you may set properties of a MaskedTextBox control. The following code snippet sets background color, foreground color, Text, Name, and Font properties of a MaskedTextBox.
The DateTimePicker control allows you to display and collect date and time from the user with a specified format.
C# datetimepicker The DateTimePicker control has two parts, a label that displays the selected date and a popup calendar that allows users to select a new date. The most important property of the DateTimePicker is the Value property, which holds the selected date and time.
dateTimePicker1.Value = DateTime.Today;
The Value property contains the current date and time the control is set to. You can use the Text property or the appropriate member of Value to get the date and time value.
DateTime iDate; iDate = dateTimePicker1.Value;
The control can display one of several styles, depending on its property values. The values can be displayed in four formats, which are set by the Format property: Long, Short, Time, or Custom.
Follow my Facebook Page : https://www.facebook.com/105940115222549 Follow me on Instagram : https://www.instagram.com/p/CViUlw2sOMi Follow me on tumblr : http://programming-guru.tumblr.com Follow me on reddit : https://www.reddit.com/u/Programming_guru1?utm_medium=android_app&utm_source=share ... https://www.youtube.com/watch?v=h7oCGfKHaSo
11946665 Bytes