473,729 Members | 2,132 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Text Input Problem

Hi
i want to know how i can make the TextBox control just accept numbers and ".";
EX:
the user can enter "1" OR "1.4"
Hope anyone could help
Thanks

Nov 28 '05 #1
6 1749
On Mon, 28 Nov 2005 07:40:03 -0800, alexmaster_2004
<al************ @discussions.mi crosoft.com> wrote:
Hi
i want to know how i can make the TextBox control just accept numbers and ".";
EX:
the user can enter "1" OR "1.4"
Hope anyone could help
Thanks


Why don't you use numericupdownco ntrol?
--
Ludwig
http://www.goedgenoegen.be
Nov 28 '05 #2
Louis, Thanks for reply.
but i want to use a textbox.

Nov 28 '05 #3

"alexmaster_200 4" <al************ @discussions.mi crosoft.com> wrote in
message news:50******** *************** ***********@mic rosoft.com...
Louis, Thanks for reply.
but i want to use a textbox.


First, please don't delete old text from the post, it means you have to look
through previous posts in the thread, rather than opening the last one :-)

Here's my suggestion:

You can do this via a two-pronged approach, using the keypress and changed
events in conjunction. First you need to look at how the value in a textbox
can be changed:

Keypress.
Paste via keyboard
Paste via context menu
Drag-drop (if implemented)
Changed in code.

In the keypress event, if the user presses a printable character and it's
not one you like, set the handled flag on the eventargs to true, as this
will stop the keypress getting into the textbox.

In the changed event handler, you need to know that the change hasn't first
been through your keypress handler with a valid character. If it has, do
nothing. If it hasn't, check if the new changed value is valid or not. If it
isn't, reset the value in the textbox to it previous (you need to store
this) valid value.

cheers

Simon
Nov 28 '05 #4
Hi,

You use KeyDown, no KeyPress

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Simon Watson" <simon dot watson at sage dot com> wrote in message
news:ek******** *****@TK2MSFTNG P09.phx.gbl...

"alexmaster_200 4" <al************ @discussions.mi crosoft.com> wrote in
message news:50******** *************** ***********@mic rosoft.com...
Louis, Thanks for reply.
but i want to use a textbox.


First, please don't delete old text from the post, it means you have to
look
through previous posts in the thread, rather than opening the last one :-)

Here's my suggestion:

You can do this via a two-pronged approach, using the keypress and changed
events in conjunction. First you need to look at how the value in a
textbox
can be changed:

Keypress.
Paste via keyboard
Paste via context menu
Drag-drop (if implemented)
Changed in code.

In the keypress event, if the user presses a printable character and it's
not one you like, set the handled flag on the eventargs to true, as this
will stop the keypress getting into the textbox.

In the changed event handler, you need to know that the change hasn't
first
been through your keypress handler with a valid character. If it has, do
nothing. If it hasn't, check if the new changed value is valid or not. If
it
isn't, reset the value in the textbox to it previous (you need to store
this) valid value.

cheers

Simon

Nov 28 '05 #5
".";
EX:
the user can enter "1" OR "1.4"
Hope anyone could help

Make sure you accept the decimal separator matching the current user locales,
not dot.
Comma is used as decimal separator in most of Europe and in many other
countries.
--
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
Nov 29 '05 #6
> "Simon Watson" <simon dot watson at sage dot com> wrote in message
news:ek******** *****@TK2MSFTNG P09.phx.gbl...

"alexmaster_200 4" <al************ @discussions.mi crosoft.com> wrote in
message news:50******** *************** ***********@mic rosoft.com...
Louis, Thanks for reply.
but i want to use a textbox.

First, please don't delete old text from the post, it means you have to
look
through previous posts in the thread, rather than opening the last one :-)
Here's my suggestion:

You can do this via a two-pronged approach, using the keypress and changed events in conjunction. First you need to look at how the value in a
textbox
can be changed:

Keypress.
Paste via keyboard
Paste via context menu
Drag-drop (if implemented)
Changed in code.

In the keypress event, if the user presses a printable character and it's not one you like, set the handled flag on the eventargs to true, as this
will stop the keypress getting into the textbox.

In the changed event handler, you need to know that the change hasn't
first
been through your keypress handler with a valid character. If it has, do
nothing. If it hasn't, check if the new changed value is valid or not. If it
isn't, reset the value in the textbox to it previous (you need to store
this) valid value.

cheers

Simon



"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us > wrote
in message news:ut******** ********@TK2MSF TNGP15.phx.gbl. .. Hi,

You use KeyDown, no KeyPress

cheers,

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


If you set handled to true on the keydown event eventargs, the character
still makes it to the textbox. If you set handled to true on the keypress
event eventargs, they key pressed is not passed on to the textbox.

As a simple example:

private void textBox1_KeyDow n(object sender,
System.Windows. Forms.KeyEventA rgs e)
{
e.Handled = true;
}

all keypresses are still propogated to the text box.

private void textBox1_KeyPre ss(object sender,
System.Windows. Forms.KeyPressE ventArgs e)
{
e.Handled = true;
}

no keypresses make it to the textbox. Also, I don't think the keydown event
will deal with keyrepeat, will it?

this was useing vs2005 release version

cheers

Simon
Nov 29 '05 #7

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

Similar topics

1
3832
by: Scott Navarre | last post by:
Hello, I have noticed that when using JavaScript to create a page, the sizes of the text input form elements come out bigger than the size I am trying to set them to. I don't know if it matters, but I am using IE6... For example: if I create a text input with a size of "1" using straight HTML, and then type into it, I can see 2 characters at a time. But when I use JavaScript's 'document.write()' function to create the same text...
2
4989
by: Kai Grossjohann | last post by:
I would like to put a text input field (in the sense of <input type="text">) and an image next to each other, where I know the size in pixels of the image, and I know the total width in em. I haven't found a way to do this. I tried <span style="width:20em"> <input type="text"> <img width="25px" src="...">
4
17594
by: j.t.w | last post by:
Hi All. I'm having a problem with my Date of Birth textbox. When I open the ..htm file, the "DoB" textbox is flat with a border. All of my other textboxes are sunken and are yellow. When I change the name of the "DoB" textbox to something like "Telephone" or "TelephoneBirthdate", the textbox changes to sunken, and yellow. I have tried changing the name to "DBirth", "BirthDate", "Birthday", "cusBirth", "DOBirth", etc. but, the...
5
3013
by: simon_s_li | last post by:
Hi, I have 5 fields in line where I need to drag and drop the text from one field to another field and then all the fields need to re-order themselves. So for instance if I drag the text in field 1 to field 3, then field 2 text and field 3 move to field 1 and field 2. I add the new order of text into an array so when the onDragEnd event
18
25003
by: Diogenes | last post by:
Hi All; I, like others, have been frustrated with designing forms that look and flow the same in both IE and Firefox. They simply did not scale the same. I have discovered, to my chagrin, that IE7 does not seem to offer any way to control the font size of a text input element.
1
2652
by: peck2000 | last post by:
Related to my earleir post ... this is the same project to re-purpose the Classifieds application in BEGINNING ASP 3.0 (Wrox) to a comicbook database ... This is a brainteaser that should have been easy to resolve but just doesn't seem to work for me ... The original application includes a form page for editing the details of an "item". In my case the item is a comicbook. The page functions just fine as long as I stick with text fields, but I...
15
5825
by: fanchun | last post by:
I already built 2 javacript files factor.js and parm.js. factor.js is an array, having several factor as elements. for example, factor.js looks like: var factor= parm.js is also an array, having coresponding parameters to those factors in factor.js file. it looks like var parm= I want to build an regression formula based on the factors and parameters in these two js file. for example, y= 0.5+x1*0.1+x2*(-0.2)+x3*0+x4*1+x5*0.3 i want to...
4
2935
cassbiz
by: cassbiz | last post by:
Could use some help here. This script is carrying over an image just fine but the text isn't coming over. can you see why it is not working???? from the form I want to carry over two lines of text and I can't find the error on why it isn't working. Any help is greatly appreciated. Here is the form
3
4319
by: dugald.morrow | last post by:
I have some javascript that updates the text in a text field after certain actions take place such as clicking a checkbox. The javascript works fine in Safari and Firefox, but in IE, the text in the text field remains empty. The page containing this problem is at the following location: http://www.skicow.com/component/option,com_skicow/act,shop/Itemid,51/debug_enabled,true The last parameter enables debug which results in alerts...
0
9428
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9291
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9218
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8163
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6026
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4536
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4799
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2699
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2171
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.