Is there a NumericBox rather than TextBox in C# compact .net

G

Gravity

Hi,

As the title indicated, any ideas?

Basically I want to have a EditBox to enter network port number. I had using
convertion from text to number, but the results messed up with the following
codes;

Byte[] f_bytePort = System.Text.Encoding.ASCII.GetBytes(textBox_Port.Text);

Int32 Port;

Port = BitConverter.ToInt32(f_bytePort, 0);

Anyone know why I got messed up results?

Anyway, if there is a numericBox, then everything is solved.
 
M

Morten Wennevik

Hi Gravity,

Using four textboxes for subscribe to the same KeyPressEventHandler and in the event check if the input character is a digit or system keys. Then simply use

Int32.Parse(textBox1.Text) to get the number.


private void TextBox_KeyPress(object sender, KeyPressEventArgs e)
{
if(!Char.IsControl(e.KeyChar) && !Char.IsDigit(e.KeyChar))
e.Handled = true;
}
 
G

Gravity

But in order to get the value, we still have to fetch TextBox.Text, which
again is String, right?

Any ideas on how to convert that string into Int32?
 
M

md

Take a look at the previous reply again:

Int32.Parse(textBox1.Text) to get the number.

Matt

Gravity said:
But in order to get the value, we still have to fetch TextBox.Text, which
again is String, right?

Any ideas on how to convert that string into Int32?
 
G

Gravity

It works! Thanks for such a straight forward solution. : )

md said:
Take a look at the previous reply again:

Int32.Parse(textBox1.Text) to get the number.

Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top