TextBoxes allow the user to input data into the program.
We are going to modify the form and add a textbox so the messagebox show us the message that the user wants. Now our form looks like:
And then modify the button click event to use the text of the textbox:
private void cmdShowMessage_Click(object sender, EventArgs e)
{
string UserText = txtUserMessage.Text;
MessageBox.Show(UserText);
}
As you can see we are using the .Text
property of the Textbox that is the text contained in the texbox.
If we run the program, we will be able to write in the textbox. When we click the button the MessageBox will show the text that we have wrote: