Dialogs in C#

At this point, we have used the mouse to enter all of the information the program needed. (Scroll bars, option buttons, check boxes, command buttons, and menu choices.)
There are some kinds of information that the user must type.
In this lesson, we will look at ways for the user to enter text.

Text Boxes: textbox

A label label is used to display information, but a textbox allows the user to enter text.

Greetings
The "Greetings" program uses a text box for the user to type his name. As the user types, the name appears (letter by letter) in the caption.

  1. Start a new Windows application and name it Greetings.
  2. Build the form as shown with a label named lblInstructions and a textbox named txtName.
  3. Write the code as shown below:
//Programmer: Janet Joy
//Illustrate using a text box
private void txtName_TextChanged(object sender, EventArgs e)
{
   this.Text = "Hello " + txtName.Text;
}

Of course, we could wait until the user presses a submit button, then retrieve all of the values from the form.

NEXT: Create the menu for the Happy Birthday App