Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Hi all,

 

I think the most used WinForms-control for input of

a number is the normal "textBox", right?

 

So the number I have put in is a string internally

which I can get if I use the .Text-property.

 

But how can I convert this to a real number like int or double?

 

To increase the number of textBox "mytxtBox" I have

to write a code like this (which works correctly):

 

if(this.mytxtBox.Text == "") this.mytxtBox.Text = "0";

currentValue = System.Convert.ToInt32(this.mytxtBox.Text);

currentValue += 3;

// to write the increased number back into the textBox:

this.mytxtBox.Text = currentValue.ToString();

 

 

My question: Am I on the right way or is there a shorter

better way to input a number in a GUI?

Edited by ToniMontana

Greetings,

 

Toni.

Posted

I'd say your on the right lines, another method for turning string's into int's would be to use this line..

 

int.Parse(textbox.Text);

Anybody looking for a graduate programmer (Midlands, England)?
  • Moderators
Posted
Yeah you're on the right track but you may want to move your first line of code into the Change or KeyPress event (if(this.mytxtBox.Text == "") this.mytxtBox.Text = "0";) whichever suits you best.
Visit...Bassic Software

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...