Home > Enterprise >  How to get user input in windows forms with array
How to get user input in windows forms with array

Time:01-04

I am coding in C# and I am trying to use windows forms. I want to do a code where it gets the coordinates from a user 10 times and puts it in a stack.


Stack mystack =new stack(); 
For(X=0,X>6,X  )
{
Int row = 0

Int column=0
Console.Writeline("enter your row");
row=Console.Readline();
Console.Writeline("Enter your column");
column=Console.Readline()
mystack.Push(row,column);

The problem is that when I try to implement console.readline and writeline in windows forms it doesn't do anything when I use it. So I'm wondering if there is a tool I can use or a way to implement this.

CodePudding user response:

You can build a few types of applications with C#; two of them are Console Applications and Windows Forms Applications.

Console Applications are just like the cmd, but with your code running in it. Therefore you can use the Console.Write, Console.WriteLine, and Console.Readline functions.

Windows Forms Application is a different kind of app that supports GUI. You can add buttons, text boxes, images, and more to build a graphical user interface where the user can interact with your application. In a Windows Forms Application you can't use the Console functions, as the console isn't available for the user.

I suggest adding two text boxes and a button to accomplish the task you want with a Windows Forms App.

  • TextBox 1: Row
  • TextBox 2: Column
  • Button: Pushes both values into the stack.

You can learn more about enter image description here

2. use this code:

        Stack mystack = new Stack();
        for (int x = 0; x < 10; x  )
        {
            int row = 0;
            int column = 0;
            Console.WriteLine("enter your row");
            row = int.Parse(Console.ReadLine());
            Console.WriteLine("Enter your column");
            column = int.Parse(Console.ReadLine());
            mystack.Push(new object[] { row, column });
        }
  • Related