Edit Masks in TextBox Controls

K

Ken Allen

Is there a way in a .Net Windows Form TextBox to define an edit mask that
controls the type of characters and values that the user may enter? Years
ago I worked with some MFC code that did this to, for example, set a mask
for an edition control that forced the display to look like a North American
phone number ("(999) 999-9999"), but I can find no way to do this in .Net --
I am probably just missing something.

I am expermimenting, and at this time I want to be able to display an edit
control for either a dollar value, a percentage or a factor ($9,999,999.99
or 999.99% or 99.9999). I want the display to reflect the intent and the
user to be restricted to entering only numeric values. I can find no mention
of the ability to do this in MSDN.

There are tons of books out there on various aspects of .Net, such as
ADO.Net and Remoting, and a ton of general books as well, but I am having
difficulty locating a good book that focuses on the Windows (and web) Forms
programming topics and how to achieve certain relatively complex tasks (such
as the edit mask approach I mention here).

Ken Allen
 
H

Herfried K. Wagner [MVP]

* "Ken Allen said:
Is there a way in a .Net Windows Form TextBox to define an edit mask that
controls the type of characters and values that the user may enter? Years
ago I worked with some MFC code that did this to, for example, set a mask
for an edition control that forced the display to look like a North American
phone number ("(999) 999-9999"), but I can find no way to do this in .Net --
I am probably just missing something.

<URL:http://www.codeproject.com/cs/miscctrl/maskedcsedit.asp>
<URL:http://www.codeproject.com/vb/net/maskedbox_control.asp>
<URL:http://www.codeproject.com/vb/net/validtext3.asp>
<URL:http://www.codeproject.com/vb/net/cpflexmaskeditbox.asp>
<URL:http://www.codeproject.com/useritems/ValidText.asp>
....

..NET 2.0 will include a masked edit control.
 
K

Ken Allen

I have checked out some of the examples that were provided, and while they
all add some degree of what I need, none of them are quite right. I guess I
shall have to build my own until .Net 2.0 is finally released into
production.

One of the issues that I am facing is that C# is the standard language
adopted here for .Net; while I can use specific sub-projects developed in
VB, this is strongly discouraged.

We would also prefer that the solution not require another assembly, if
possible. One project I am working on is required (for various internal and
not completely technical reasons) to be a single executable, and so any
custom work must be embedded within the project and not as a separate
assembly -- and I would like to have masked edit controls for this project.

All of the examples that I have seen are focused on permitting strings to be
controlled via a custom Textbox sub-class, but what I need is the ability to
have binary (integer and floating point) values properly formatted and
displayed and have the edit control display detailed masked editing -- but I
need to be able to retrieve a numeric value from the edited Textbox
sub-class control. The existing controls are focused on text only.

The VB example comes the closest to what I need, since the edit mask and the
display of the data are separate, but it is VB when I need embedded C#, and
it still does not provide me with easy binary input/output.

Ah well.

-ken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

How do I mask the input of a Text Box in VB.NET 2
Masks in Excel 2
Input Masks 1
TextBox Control 1
Exclamation mark in Input masks 1
Formatting a textbox 1
Input/Display Masks?? 1
Input/Display Masks C# 1

Top