473,322 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Field limit masking ?

Here is te problem. I have a text box that I only allow numbers or decimals
to be entered (using an event delegate). The max number of characters I
allow is 4. The highest number that they should be able to enter is 1.25
and the lowest is 0.010. Currently I check the field when the leave the
control, but I need to not allow them to enter "9999" when they are typing
and not ust when they leave. Can anyone think of a way to do this?
Nov 16 '05 #1
6 1548
John,

You might want to attach to the TextChanged event on the textbox, which
will notify you when text is changed. You should be able to make a
determination here when the text is not in a format that you want.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"John Sutor" <jo********@cinfin.com> wrote in message
news:e2**************@TK2MSFTNGP10.phx.gbl...
Here is te problem. I have a text box that I only allow numbers or decimals to be entered (using an event delegate). The max number of characters I
allow is 4. The highest number that they should be able to enter is 1.25
and the lowest is 0.010. Currently I check the field when the leave the
control, but I need to not allow them to enter "9999" when they are typing
and not ust when they leave. Can anyone think of a way to do this?

Nov 16 '05 #2
John,

You might want to attach to the TextChanged event on the textbox, which
will notify you when text is changed. You should be able to make a
determination here when the text is not in a format that you want.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"John Sutor" <jo********@cinfin.com> wrote in message
news:e2**************@TK2MSFTNGP10.phx.gbl...
Here is te problem. I have a text box that I only allow numbers or decimals to be entered (using an event delegate). The max number of characters I
allow is 4. The highest number that they should be able to enter is 1.25
and the lowest is 0.010. Currently I check the field when the leave the
control, but I need to not allow them to enter "9999" when they are typing
and not ust when they leave. Can anyone think of a way to do this?

Nov 16 '05 #3
Hi John,
In such scenario I think it's better to intercept the KeyPressed (raised
before the control's value is updated) event, then you can decide if the key
is valid using the current value of the control and the new key pressed.

Pd:
I think that if you look in google by "numeric textbox" you will find a
similar solution

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"John Sutor" <jo********@cinfin.com> wrote in message
news:e2**************@TK2MSFTNGP10.phx.gbl...
Here is te problem. I have a text box that I only allow numbers or decimals to be entered (using an event delegate). The max number of characters I
allow is 4. The highest number that they should be able to enter is 1.25
and the lowest is 0.010. Currently I check the field when the leave the
control, but I need to not allow them to enter "9999" when they are typing
and not ust when they leave. Can anyone think of a way to do this?

Nov 16 '05 #4
Hi John,
In such scenario I think it's better to intercept the KeyPressed (raised
before the control's value is updated) event, then you can decide if the key
is valid using the current value of the control and the new key pressed.

Pd:
I think that if you look in google by "numeric textbox" you will find a
similar solution

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"John Sutor" <jo********@cinfin.com> wrote in message
news:e2**************@TK2MSFTNGP10.phx.gbl...
Here is te problem. I have a text box that I only allow numbers or decimals to be entered (using an event delegate). The max number of characters I
allow is 4. The highest number that they should be able to enter is 1.25
and the lowest is 0.010. Currently I check the field when the leave the
control, but I need to not allow them to enter "9999" when they are typing
and not ust when they leave. Can anyone think of a way to do this?

Nov 16 '05 #5
John

Try this two events.

private void textBox1_KeyPress(object sender,
System.Windows.Forms.KeyPressEventArgs e)
{
//allow only digits and decimal
if((char.IsDigit(e.KeyChar) ==true) || (e.KeyChar == '.'))
e.Handled = false;
else
e.Handled = true;
}

private void textBox1_Leave(object sender, System.EventArgs e)
{
//handle special case validation while leaving the text box.
double number = Convert.ToDouble(textBox2.Text.Trim());
if((number < 0.010) || (number > 1.25))
MessageBox.Show("Invalid entry");
}

Shak

"John Sutor" <jo********@cinfin.com> wrote in message
news:e2**************@TK2MSFTNGP10.phx.gbl...
Here is te problem. I have a text box that I only allow numbers or decimals to be entered (using an event delegate). The max number of characters I
allow is 4. The highest number that they should be able to enter is 1.25
and the lowest is 0.010. Currently I check the field when the leave the
control, but I need to not allow them to enter "9999" when they are typing
and not ust when they leave. Can anyone think of a way to do this?

Nov 16 '05 #6
John

Try this two events.

private void textBox1_KeyPress(object sender,
System.Windows.Forms.KeyPressEventArgs e)
{
//allow only digits and decimal
if((char.IsDigit(e.KeyChar) ==true) || (e.KeyChar == '.'))
e.Handled = false;
else
e.Handled = true;
}

private void textBox1_Leave(object sender, System.EventArgs e)
{
//handle special case validation while leaving the text box.
double number = Convert.ToDouble(textBox2.Text.Trim());
if((number < 0.010) || (number > 1.25))
MessageBox.Show("Invalid entry");
}

Shak

"John Sutor" <jo********@cinfin.com> wrote in message
news:e2**************@TK2MSFTNGP10.phx.gbl...
Here is te problem. I have a text box that I only allow numbers or decimals to be entered (using an event delegate). The max number of characters I
allow is 4. The highest number that they should be able to enter is 1.25
and the lowest is 0.010. Currently I check the field when the leave the
control, but I need to not allow them to enter "9999" when they are typing
and not ust when they leave. Can anyone think of a way to do this?

Nov 16 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: F. Barth | last post by:
Hello, I've posted this problem to one other newsgroups, and gotten some diagnostic help, but I still need a solution. The full text of the message box is: "The field is too small to accept the...
0
by: John Sutor | last post by:
Here is te problem. I have a text box that I only allow numbers or decimals to be entered (using an event delegate). The max number of characters I allow is 4. The highest number that they...
6
by: marktxx | last post by:
Although the C90 standard only mentions the use of 'signed int' and 'unsigned int' for bit-fields (use 'int' at your own risk) and C99 adds _Bool. It seems that most compilers create the size of...
9
by: Daniel Smedegaard Buus | last post by:
Hey all :) I was wondering about the $error_types (I particularly notice the 's' suffix when reading the manual) parameter for 'set_error_handler()': Can be used to mask the triggering of the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.