Click here to Skip to main content
Click here to Skip to main content

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

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

RedPhoenix.net
Web Developer
United States United States
No Biography provided

Comments and Discussions

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

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

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

| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 8 Oct 2006
Article Copyright 2006 by RedPhoenix.net
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid