?
Solved

MaskedEditTextbox mask numeric

Posted on 2009-04-21
14
Medium Priority
?
793 Views
Last Modified: 2013-11-26
I am using an MaskedEditTextbox but i am having trouble with the mask.
I want the user to be able to input the following mask
999990.0

Min 1.0
max 999999.9
but when the user wants to input 12.4 it has to input first "12" then a lot of spaces then the ".4"
Is there a mask that allows 1.0 as wel as 999999.9
0
Comment
Question by:dgb
  • 6
  • 5
11 Comments
 

Author Comment

by:dgb
ID: 24203497
Hi Vee_Mod,

Still getting used to the new way of asking questions.

This question is reagarding Microsoft visual studio 2005 (.NET)
0
 
LVL 39

Expert Comment

by:abel
ID: 24203652
Is this in Windows Forms application or in a ASP.NET application? Both have MaskedTextBox...
           

0
 
LVL 39

Expert Comment

by:abel
ID: 24203669
Either way, the mask you are after is "#####0.0"
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 

Author Comment

by:dgb
ID: 24204879
I've already tryed the "#" instead of the "0" but it doesn't work.
you still need to type spaces
(typing the "." or "," doesn't result in skipping to decimal side)
0
 
LVL 39

Expert Comment

by:abel
ID: 24205603
Can you answer my other question too, please? Then I can try to mimic your situation without being on the wrong track. If you use ASP.NET, please post the declarative part (aspx) code you have so far.

> (typing the "." or "," doesn't result in skipping to decimal side)
I don't understand what you mean here.


0
 

Author Comment

by:dgb
ID: 24208685
it is vb.net 2005 on vista

>> (typing the "." or "," doesn't result in skipping to decimal side)

>I don't understand what you mean here.

What i mean is that if i type "12.1" it stops with "12"
I can only type spaces until i reach the decimal sign than i can type the ".1"
0
 
LVL 39

Expert Comment

by:abel
ID: 24209050
> it is vb.net 2005 on vista

that was not the other question I meant. Do you use ASP.NET with VB.NET or do you use WinForms with VB.NET?

but from your description I understand winforms, so I will continue with that for a moment.
0
 

Author Comment

by:dgb
ID: 24209435
Correct i am using winforms
0
 
LVL 39

Accepted Solution

by:
abel earned 2000 total points
ID: 24209640
Hmm, the question is, should you really use the masked edit for this? It is meant for input that requires a certain defined mask, i.e., for a fixed length.

Anyway, here's a solution (better, a workaround), using the keypress event and using "######.#" as a mask. It will react on the decimal (assuming a dot) and will change the value to match the digits typed so far and it will place the cursor after the dot.

Private Sub MaskedTextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MaskedTextBox1.KeyPress
If e.KeyChar = "."c Then
    Dim len As Integer = MaskedTextBox1.Text.Length
    Dim s As String = MaskedTextBox1.Text.Replace(" ", "")
    MaskedTextBox1.Text = s.PadLeft(len)
    MaskedTextBox1.SelectionStart = MaskedTextBox1.Mask.Length - 1
End If
End Sub

Open in new window

0
 

Author Comment

by:dgb
ID: 24209713
I have tested the code and it works.
Thanks for the workaround
As you pointed out maskedtextbox is not that handy for numeric input but on the other hand dates
are a different story.

Anyways thanks for the help

ps if you have an better solution wich works for numeric input as well dates please let me know.






0
 
LVL 39

Expert Comment

by:abel
ID: 24210425
glad I could help :)

If you need both in one control, I'd create my own based on a text control, but that's just me. For your current situation it only takes a few lines to workaround, so you're easily set. I'd stick to that unless you need more special behavior.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question