Database Reference
In-Depth Information
Figure 9-10. Running the Windows Application form
How It Works
Visual Studio comes with a lot of features to help developers while writing code. One of these features is
that you can just double-click the GUI element for which you want to add the code, and you will be
taken to the code associated with the GUI element in the Code view. For example, when you double-
click the Submit button in the Design view, you are taken to the Code view, and the btnSubmitClick
event template automatically gets generated.
To achieve the functionality for this control, you add the following code:
MessageBox.Show("Hello" + ' ' + txtFname.Text + ' ' + txtLname.Text + ' ' +
"Welcome to the Windows Application","Welcome", MessageBoxButtons.OKCancel,
MessageBoxIcon.Information);
MessageBox.Show() is a .NET Windows Forms method that pops up a message box based on
provided arguments. To display a “Welcome” message with the first name and last name specified by the
user in the message box, you apply a string concatenation approach while writing the code.
In the code segment, you hard-code the message “Hello Welcome to the Windows Application,” but
with the first name and last name of the user appearing after the word Hello and concatenated with the
rest of the message, “Welcome to the Windows Application.”
For readability, you also add single space characters ( '' ) concatenated by instances of the +
operator in between the words and values you are reading from the Text property of txtFnam and
txtLname . If you do not include the single space character ( '' ) during string concatenation, the words
will be run into each other, and the message displayed in the message box will be difficult to read.
 
Search WWH ::




Custom Search