winforms Basic controls TextBox

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

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:

enter image description here

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:

enter image description here



Got any winforms Question?