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

  • Thread starter Thread starter Gravity
  • Start date Start date
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.
 
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;
}
 
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?
 
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?
 
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
 
Back
Top