Click here to Skip to main content
13,193,468 members (41,117 online)
Click here to Skip to main content
Add your own
alternative version


29 bookmarked
Posted 22 Apr 2006

Another MaskEditBox in C#

, 7 Oct 2006
Rate this:
Please Sign up or sign in to vote.
MaskEditBox in C# w/ support for cut, copy, and paste.

Sample Image - MaskEditBox.jpg


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:

,Comma (or thousands separator)
/Forward slash
()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).


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.


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.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author
Web Developer
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

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

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171018.2 | Last Updated 8 Oct 2006
Article Copyright 2006 by
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid