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 6 1736
On Mon, 28 Nov 2005 07:40:03 -0800, alexmaster_2004
<al************@discussions.microsoft.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 numericupdowncontrol?
--
Ludwig http://www.goedgenoegen.be
Louis, Thanks for reply.
but i want to use a textbox.
"alexmaster_2004" <al************@discussions.microsoft.com> wrote in
message news:50**********************************@microsof t.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
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*************@TK2MSFTNGP09.phx.gbl... "alexmaster_2004" <al************@discussions.microsoft.com> wrote in message news:50**********************************@microsof t.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
"."; 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
> "Simon Watson" <simon dot watson at sage dot com> wrote in message news:ek*************@TK2MSFTNGP09.phx.gbl... "alexmaster_2004" <al************@discussions.microsoft.com> wrote in message news:50**********************************@microsof t.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.machin AT dot.state.fl.us> wrote
in message news:ut****************@TK2MSFTNGP15.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_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{
e.Handled = true;
}
all keypresses are still propogated to the text box.
private void textBox1_KeyPress(object sender,
System.Windows.Forms.KeyPressEventArgs 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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...
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
| |
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,...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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,...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |