Reputation: 1031
I'm trying to make my console application into a winforms application.
The console version would ask for multiple inputs, then return output.
For the winforms version, I want to have multiple text boxes for the user to enter the data, with a button to reset them all, and another to actually perform the calculation. Then there'd be a display to show the result (I'm guessing it would be another text box).
Basically I've figured out how to add the buttons and text boxes for input/calculation, but I'm not sure how to display the output, or add functionality to all of this.
Edit: Should I be using Masked Text Boxes if I want to keep the user from using invalid input (anything that isn't a positive integer)?
Upvotes: 0
Views: 434
Reputation: 19601
Start by looking here: http://www.codeproject.com/KB/books/1861004982.aspx, it's a little old but still relevant.
Also have a look on the official Microsoft site: http://windowsclient.net/learn/videos.aspx
GUI development is tricky, fun and exciting, all at the same time!
EDIT: I should point out I'm linking to things because at this point, being able to learn a new technology (such as WinForms) by yourself, from documentation and the internet, is invaluable to your future skills development.
Upvotes: 2
Reputation: 1536
public partial class Form2 : Form
{
Button reset = new Button();
Button compute = new Button();
Panel pnl = new Panel();
public Form2()
{
reset.Text = "reset";
compute.Text = "compute";
pnl.Name = "pnl";
reset.Click += new EventHandler(reset_Click);
compute.Click += new EventHandler(compute_Click);
this.Controls.Add(compute);
this.Controls.Add(reset);
this.Controls.Add(pnl);
init();
foreach (Control ctl in this.Controls)
{
ctl.Dock = DockStyle.Top;
}
}
void compute_Click(object sender, EventArgs e)
{
int tot=0;
foreach (TextBox txt in pnl.Controls)
{
tot += int.Parse(txt.Text);
}
MessageBox.Show("total is:" + tot.ToString());
}
void reset_Click(object sender, EventArgs e)
{
foreach (TextBox txt in pnl.Controls)
{
txt.Text = "0";
}
}
private void init()
{
pnl.Controls.Clear();
//5 textbox
for (int i = 0; i <= 5; i++)
{
TextBox t = new TextBox();
t.Dock = DockStyle.Top;
t.Text = "0";
this.Controls["pnl"].Controls.Add(t);
}
}
}
Upvotes: 0