473,665 Members | 2,798 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 1745
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
3813
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
4979
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
17584
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
2992
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
24953
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
2637
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
5812
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
2921
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
4309
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
8438
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8348
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8779
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
6187
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5660
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
4186
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
4356
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2004
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1761
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.