0

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)?

Slateboard
  • 1,031
  • 6
  • 15
  • 31
  • If you want to display only positive integer you should take a NumericUpDown or at http://stackoverflow.com/questions/508533/numeric-textbox or ... – Oliver Mar 04 '10 at 07:12

3 Answers3

2

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.

Alastair Pitts
  • 19,423
  • 9
  • 68
  • 97
0

How about adding another readonly textbox to display output?

Pierreten
  • 9,917
  • 6
  • 37
  • 45
  • I think that will work. I just need to figure out how to make it all function as it's a lot different than a console app. – Slateboard Mar 04 '10 at 04:59
0
 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);                
            }
        }

    }
NET Experts
  • 1,525
  • 17
  • 35