Convert TextBox input to double value
using System;
using System.Drawing;
using System.Windows.Forms;
public class EnterPrice : Form {
private Button enter = new Button();
private Label answer = new Label();
private TextBox text = new TextBox( );
public EnterPrice( ) {
enter.Text = "Enter Price";
text.Text = "";
answer.Text = "";
Size = new Size(300,200);
answer.Size = new Size(200,50);
enter.Location = new Point(30 + enter.Width, 30);
text.Location = new Point (40 + enter.Width + enter.Width, 30);
answer.Location = new Point(20, 60);
AcceptButton = enter;
Controls.Add(text);
Controls.Add(answer);
Controls.Add(enter);
enter.Click += new EventHandler(Enter_Click);
}
protected void Enter_Click(Object sender, EventArgs e) {
try{
Console.WriteLine(Double.Parse(text.Text));
}catch(Exception){
}
text.Text = "";
text.Focus();
}
static void Main() {
Application.Run(new EnterPrice());
}
}
Related examples in the same category