• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

C# Need help with windows forms

Krishot7

New Coder
I made a simple talking program when I just started learning c#. Now I am an average and know a bit about this language, and I decided to take my old program (Which was a console application) and made a new windows forms app with an Input field to Simulate Console.Readline and Output for WriteLine and a next button to move forward and submit what's there in the input field. I completed the code and made 2 lines 'Hi and What's your name' just for testing and while it should have worked, it didn't. Here's the code-
C#:
using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;



namespace WinFormsApp1

{

    public partial class Form1 : Form

    {



        public bool SubmitClick;

        public int ConvNum;



        public Form1()

        {

            InitializeComponent();



            ConvNum = 1;



            if (ConvNum == 1)

            {

                OutputText.Text = "Hi";

            }



            if (ConvNum == 2)

            {

                OutputText.Text = "What is your name?";

            }

        }



        private void button1_MouseClick(object sender, MouseEventArgs e)

        {

            InputText.Text = " ";

            SubmitClick = true;

            ConvNum = ConvNum + 1;

        }

    }

}
 

Krishot7

New Coder
By the way, here is the old program I made watching Brackeys' C# course
C#:
using System;

namespace Talketive_Machine
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WindowHeight = 30;
            Console.WindowWidth = 100;
            Console.Title = "Talking Machine";

            Console.WriteLine("Hi what is your name?");

            string userName = (Console.ReadLine() );

            Console.WriteLine("Hi " + userName + "\n I am an AI");
            Console.WriteLine("So what is your favorite activity? Mine is making people happy :)");

            string favoriteHobby = (Console.ReadLine() );

            Console.WriteLine("Cool! I also like " + favoriteHobby + "!");
            Console.WriteLine("So how can I help you?");

            Console.ReadLine();

            Console.WriteLine("Are you sad, bored or happy?");

            string emotion = Console.ReadLine();

            switch (emotion)
            {
                case "sad" or "Sad":
                    Console.WriteLine("I can tell you a joke. This will cheer you up. \nWhat do you call it when a dinosaur crashes his car?");
                    Console.ReadLine();
                    Console.WriteLine("Tyrannosaurus wrecks!");
                    break;

                case "bored" or "Bored":
                    Console.WriteLine("Lets Play a Quiz!");
                    Console.WriteLine("What is the capital of Russia?");

                    string boredQuizAnswer = Console.ReadLine();
                    {
                       switch (boredQuizAnswer)
                        {
                            case "moscow" or "Moscow":
                                Console.WriteLine("Correct!");
                                break;

                            default:
                                Console.WriteLine("Wrong Answer");
                                break;
                        }
                    }
                    break;

                case "happy" or "Happy":
                    Console.WriteLine("Then why are you even here?");
                    break;
            }

            Console.Write("Nice! So what is your favourite food?");

            string favoriteFood = Console.ReadLine();

            Console.WriteLine("Oh! " + favoriteFood + " tasty! my favourite food is Electricity!");

            Console.WriteLine("So do you want to learn something new?");

            string learnNew1 = Console.ReadLine();

            switch (learnNew1)
            {
                case "Yes" or "yes" or "YES" or "yES" or "yeS" or "YeS" or "yEs":
                    Console.WriteLine("The strongest muscle in the body is the tongue.");
                    break;

                case "no" or "No" or "NO":
                    Console.WriteLine("Ok");
                    break;
            }
           
            Console.ReadKey();
        }
    }
}
 

Top