473,386 Members | 1,708 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,386 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 1551
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.