ToniMontana Posted March 19, 2004 Posted March 19, 2004 (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 March 19, 2004 by ToniMontana Quote Greetings, Toni.
Cags Posted March 19, 2004 Posted March 19, 2004 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); Quote Anybody looking for a graduate programmer (Midlands, England)?
Moderators Robby Posted March 19, 2004 Moderators Posted March 19, 2004 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. Quote Visit...Bassic Software
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.