Click here to Skip to main content
15,892,480 members
Articles / Programming Languages / C#

Another MaskEditBox in C#

Rate me:
Please Sign up or sign in to vote.
3.67/5 (9 votes)
7 Oct 2006CPOL2 min read 54K   371   29   6
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
0Fixed number format
#,##0Commas format
0%Percent format
0.00E+00Scientific format
cGeneral Date and Time format
ddddddLong Date format
dd-mmm-yyMedium Date format
dddddShort Date format
tttttLong Time format
hh:mm AM/PMMedium Time format
hh:mmShort 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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralBug with FormatSelector? [modified] Pin
terrytester17-Jul-06 16:12
terrytester17-Jul-06 16:12 
GeneralRe: Bug with FormatSelector? Pin
RedPhoenix.net7-Oct-06 18:31
RedPhoenix.net7-Oct-06 18:31 
General"Culture" question Pin
Paolo Pagano9-May-06 3:12
Paolo Pagano9-May-06 3:12 
GeneralQuestion for anyone.... Pin
RedPhoenix.net23-Apr-06 11:34
RedPhoenix.net23-Apr-06 11:34 
GeneralRe: Question for anyone.... Pin
chmod7551-May-06 16:30
chmod7551-May-06 16:30 
GeneralRe: Question for anyone.... Pin
RedPhoenix.net1-May-06 22:14
RedPhoenix.net1-May-06 22:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.