By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,979 Members | 943 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,979 IT Pros & Developers. It's quick & easy.

how to get numeric input in winForm

P: n/a
Sam
Why isn't there a numberBox Windows Form control like a
textbox control but for numeric (float) input? There
doesn't seem to be any easy or visual solution to this
VERY SIMPLE ISSUE in either version of Visual Studio. I
simply wanted to create a Windows app where a user could
enter miles or kilometers, gallons or liters, and see the
other in the adjacent box. The form was easy but the
textbox control would not let me cast any number of any
kind from textbox.text and of course, input validation is
a pain since there is no built-in masking capability.
Validating keystrokes becomes too complex because it
doesn't handle backspace, paste or any other interaction.
Hours of searching help resulted in nothing useful
whatsoever. The Numeric boolean attribute of Textbox
documented in help isn't recognized by Vis Studio. Is
this a bug or just poor documentation?

Must I reinvent the wheel to get a number from a form
control? Please reply with C# code sample, if possible.
Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On KeyDown, check the value of e. Here's an example of it. You can create
a custom control and never worry about it again. It's not complex at all.
As a matter of fact, you can even take this code, compile it into your own
control, and be done with it. But don't do that. First read through it ;-)

Cheers,

Bill
"Sam" <tr*******@hotmail.com> wrote in message
news:06****************************@phx.gbl...
Why isn't there a numberBox Windows Form control like a
textbox control but for numeric (float) input? There
doesn't seem to be any easy or visual solution to this
VERY SIMPLE ISSUE in either version of Visual Studio. I
simply wanted to create a Windows app where a user could
enter miles or kilometers, gallons or liters, and see the
other in the adjacent box. The form was easy but the
textbox control would not let me cast any number of any
kind from textbox.text and of course, input validation is
a pain since there is no built-in masking capability.
Validating keystrokes becomes too complex because it
doesn't handle backspace, paste or any other interaction.
Hours of searching help resulted in nothing useful
whatsoever. The Numeric boolean attribute of Textbox
documented in help isn't recognized by Vis Studio. Is
this a bug or just poor documentation?

Must I reinvent the wheel to get a number from a form
control? Please reply with C# code sample, if possible.

Nov 15 '05 #2

P: n/a
This is one of those areas where I really think WinForms is lacking (as you
could quite easily do this back in the MFC days). Maybe they'll extend
textbox in upcoming versions? For now though Ignacio's solution strikes me
as the cleanest :)

Kieran

"Sam" <tr*******@hotmail.com> wrote in message
news:06****************************@phx.gbl...
Why isn't there a numberBox Windows Form control like a
textbox control but for numeric (float) input? There
doesn't seem to be any easy or visual solution to this
VERY SIMPLE ISSUE in either version of Visual Studio. I
simply wanted to create a Windows app where a user could
enter miles or kilometers, gallons or liters, and see the
other in the adjacent box. The form was easy but the
textbox control would not let me cast any number of any
kind from textbox.text and of course, input validation is
a pain since there is no built-in masking capability.
Validating keystrokes becomes too complex because it
doesn't handle backspace, paste or any other interaction.
Hours of searching help resulted in nothing useful
whatsoever. The Numeric boolean attribute of Textbox
documented in help isn't recognized by Vis Studio. Is
this a bug or just poor documentation?

Must I reinvent the wheel to get a number from a form
control? Please reply with C# code sample, if possible.

Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.