Wednesday, May 4, 2016

Program 2: Concatenate text from Textboxes and display in a Message Box


1. Open Visual studio 2013 or any other version.
2. On the menu bar, choose File, New, and Project.
3. Choose Programming language as  Visual C# . In the templates list, choose the Windows     Forms Application icon.
4. Name the project as required and specify the address of your folder.
5. In the main window design the form as shown below.

The above figure contains two Textbox, two Labels and two Buttons. All these controls are named as required. The naming can be done through the property window of each control.
SurName and Name are labels. Name of the buttons are btnshow and btncancel. Name of the textboxes are txtsurname and txtname.

     Double click the Show  button and  write the following code
private void btnShow_Click(object sender, EventArgs e)
 {
  MessageBox.Show("Your Full name is " + txtsurname.Text + " " + txtname.Text);
     }
4.   
    Double click the Cancel  button and  write the following code
private void btnCancel_Click(object sender, EventArgs e)
        {
           Application.Exit();
          
        }
 Run your program  and check the result 

Explanation:

MessageBox.Show will display the message in a message box. It will concatenate the text from both the textbox and is displayed .

have fun with programming..

No comments:

Post a Comment