Beginner's Guide to C# Programming: A Practical Approach in Visual Studio by Serhan Yamacli

Beginner's Guide to C# Programming: A Practical Approach in Visual Studio by Serhan Yamacli

Author:Serhan Yamacli [Yamacli, Serhan]
Language: eng
Format: epub
Published: 2017-07-02T07:00:00+00:00


Let’s use an if statement in an example where the user will enter a

username and a password. Our program will check if they are valid:

1. Create a C# project.

2. Add three Labels, two TextBoxes and one Button on the form as in

Figure 8.17.

3. Set the Text of the first Label as Login window.

4. Set the Texts of the second and third Labels as Username: and

Password:.

223

BEGINNER’S GUIDE TO C# PROGRAMMING

Figure 8.17. Layout of the form

5. Set the Name properties of TextBoxes as usernameTextBox and

passwordTextBox, respectively.

6. Set the Name and Text of the Button as Login and loginButton.

7. Double-click the Button to create its Click event handler method as

usual. We will use the if statement inside this method. We don’t have

a database yet therefore let’s compare the username and password

against constant values such as csharpprogrammer and abc456,

respectively. We do this in the if statement as follows:

if (usernameTextBox.Text == "csharpprogrammer" &&

passwordTextBox.Text == "abc456")

{

MessageBox.Show("Login successful");

}

Code 8.15



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.