Reputation: 11
So iv been creating text adventures on the console but I want to move on to the windows form, but im stuck, I like using switch statements for the text adventure so one console I just need to put...
Console.readline();
but with windows forms it different, how do I make it so when I hit the button,it copies the text in the box(the smaller one) and then run a switch statement? I tried searching everywhere but I cant find it, putting a switch in a loop just freezes the program, and just having the switch statement skips it. here is an example...
string choice;
choice = userInputBox.Text;
switch (choice)
{
case choice1:
{
//event n stuff
}
case choice2:
{
//event n stuff
}
}
but it runs the switch before the player cant type any input. What I want is for the program to wait until the player hits confirm to confirm there choice, then run the switch, and also have the button useable for different switch statements.
Upvotes: 0
Views: 1767
Reputation: 2053
Look at event handlers. Assign the logic to the buttons onClick event. Replace these handlers with alternatives.
Upvotes: 1
Reputation: 101681
It seems you need to use Button control. Add a button control to your form with designer from toolbox. Then double click your button,and write your code inside the button_Click
event
private void button1_Click(object sender, EventArgs e)
{
string choice;
choice = userInputBox.Text;
switch (choice)
{
case choice1:
{
//event n stuff
}
case choice2:
{
//event n stuff
}
}
}
Also take a look at this tutorial: http://msdn.microsoft.com/en-us/library/dd492173.aspx
Upvotes: 4