I’m trying rewrite game “guess word” from C# console to C# windows form, and I have 1 problem I don’t know how to stop loop ant 2 time read word from textbox
while (true)
{
guess.Text = Console.ReadLine(); // how to stop loop here and read new word from textbox?
if (guess.Text=="#")
break;
if (guess.Text.CompareTo(secretWord) == 0)
{
bGuessedCorrectly = true;
break;
In a Windows Forms application, the main loop is actually already maintained by the form and operation system. The form will fire events when user input is detected, such as a mouse click or a keystroke. You, as a developer of the GUI (Graphical User Interface), subscribe to an event that you’re interested in, like a “submit” button click, and then run the appropriate logic.
Usually, When developing a UI, you would use a designer which is a tool in your IDE (e.g. Visual Studio) which allows you to design the layout of your controls (buttons, checkboxes etc.). In Visual studio, double-clicking a control, will subscribe to the default event of that control (in the case of a button, it will subscribe to a click event and will even generate an event handler (a method), to write the logic for that event: