Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Another MaskEditBox in C#

0.00/5 (No votes)
7 Oct 2006 1  
MaskEditBox in C# w/ support for cut, copy, and paste.

Sample Image - MaskEditBox.jpg

Introduction

This is a recreation of the VB6 MaskEdBox (COM control) for Visual Studio .NET 2003. Supports cut, copy, and paste, and also allows you to set the Mask and Text properties of the control. Here is a list of the supported mask chars:

Normal mask chars:

. Decimal
, Comma (or thousands separator)
: Colon
/ Forward slash
- Minus
() Left and right parenthesis

Special mask chars:

> Greater than (Lowercase)
< Less than (Uppercase)
\ Backslash (Literal handler)

You will notice that the mask that gets displayed in run mode versus design mode is the same, as in VB6 it actually had the mask displayed in design mode and the input mask displayed during runtime. This MaskEditBox just displays the input mask (minor detail).

Note

When the user pastes text into the MaskEditBox, if there are illegal chars within the clipboard, those chars will be stripped. For instance, in the clipboard is the text "555ABC9874", and the Mask property is set to (###)###-####. Then, the result that will be displayed is "(555)___-8974". This will also happen when you set the Text property of the control: MaskEditBox1.Text = "555ABC9874";.

If you like this control, please rate it. Any questions, comments, or bugs, just post them below. If the ratings are low or there are no comments for this control, then any updates will not be on my high priority list of to-do things. So please take time out to rate or comment this control. Please feel free to email me if needed.

History

Update: 04/23/2006

Control now supports the backslash literal handler. Also fixed some minor bugs where the keys being pressed would not show due to mask restrictions not implemented correctly.

Update: 05/01/2006

Added the Format property: you can now select from 12 different formats, each as the original. This property does not allow for custom format types. The format selected and implemented must be within the list. Also note that working with dates and times with this control's Format property does not behave the same. How Microsoft was able to get 06-Jan-00 just from the number 7 is beyond me!

Supported formats:

$#,##0.00;($#,##0.00) Currency format
0 Fixed number format
#,##0 Commas format
0% Percent format
0.00E+00 Scientific format
c General Date and Time format
dddddd Long Date format
dd-mmm-yy Medium Date format
ddddd Short Date format
ttttt Long Time format
hh:mm AM/PM Medium Time format
hh:mm Short Time format

Added the ClippedText method (same as ClipText in VB6).

Update: 05/04/2006

Fixed a small bug where if the OnKeyDown or OnKeyPress was checked for set key events. They would not respond due to the events being overridden.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here