Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
128 views

Lab3 WindowForms EN

The document describes how to create a Windows Form application in C# that simulates a security panel. The form includes numeric buttons to enter an access code and a submit button. When the submit button is clicked, the code is checked against valid codes for technicians, custodians and scientists. If valid, the date, time and user group are displayed. If invalid, a restricted access message is shown. The form is designed with labels and textboxes to display the login information. Event handlers are created to handle number button clicks and submit button click to check the access code and display the results.

Uploaded by

Long Híp
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
128 views

Lab3 WindowForms EN

The document describes how to create a Windows Form application in C# that simulates a security panel. The form includes numeric buttons to enter an access code and a submit button. When the submit button is clicked, the code is checked against valid codes for technicians, custodians and scientists. If valid, the date, time and user group are displayed. If invalid, a restricted access message is shown. The form is designed with labels and textboxes to display the login information. Event handlers are created to handle number button clicks and submit button click to check the access code and display the results.

Uploaded by

Long Híp
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 18

WindowsForm using C# 2020

EXERCISE 1
Windows Form Application – Basic

* Content:
- Create a basic Windows Form application that calculates the service charge for a dentist
visit.
- For each customer, the services provided include: teeth removal, lime shaving, dental
imaging and fillings. Each type will have its own cost. Finally, the total cost of the guest
must pay. Note: only charge when the customer name information has been entered (if
this information is not available, the program generates MessageBox alert).
- The application has a simple interface below.

Guideline:
1. Create a Windows Form application named DentalPaymentApp by following these steps
a. Create a new project (Ctrl+Shift +N),
b. In the new project window select Visual C # .Net - Windows
c. For the template section, select Windows Forms Application
d. Set name of the project in the Name section
2. After completing the steps on VS.NET will generate a sample Windows Form project,
allowing programmers to start building applications. The interface of VS.NET 2005 for the
newly created application is as shown in Figure 3 below.

FPT University Collection and Edit


7/19/2021Created by X31
WindowsForm using C# 2020

3. Design the form according to the following description


Table 1: Describe the controls on the form
No Name Control Set properties for the control
1 lblTitle Label Text = “Dental Payment Form”, Font =
“Impact, Size = 17”, ForeColor = Blue
2 lblName Label Text = “Customer name”
3 txtName TextBox
4 chkClean CheckBox Text = “Cạo vôi”
5 lblCleanCost Label Text=”$100000”
6 chkWhitening CheckBox Text=”Tẩy trắng”
7 lblWhiteningCost Label Text=”$1200000”
8 chkXRay CheckBox Text=”Chụp hình răng”
9 lblXRayCost Label Text=”$200000”
10 lblFilling Label Text=”Trám răng”
11 numFilling NumericUpDown
12 lblFillCost Label Text=”$80000”
13 lblTotal Label Text=”Total”
14 txtTotal TextBox Enable = False
15 btnExit Button Text=”Thoát”
16 btnCalc Button Text=”Tính tiền”

FPT University Collection and Edit


7/19/2021Created by X31
WindowsForm using C# 2020

Doing:

Illustrate the renaming of TextBox on the Form


4. Create a click event handler for the "Exit" button: this function will execute the application
when finished (closing the form)

FPT University Collection and Edit


7/19/2021Created by X31
WindowsForm using C# 2020

How to create event handlers: can do one of two ways


- Way 1: Double click the button to create event handler in the screen Form design view:
then VS will create event handler associated with the event Click of the button "Exit"

- Way 2: Select the button to create a handler, then click the event tab in the Properties
window, double click the Click item in the event window.

FPT University Collection and Edit


7/19/2021Created by X31
WindowsForm using C# 2020

1. Create a cash register function, this function is activated when the "Cash register" button
is selected. Describe the GetPay () function as follows (GetPay () is a member method of the
main Form class:
+ Check if the customer name is entered or not?
+ If not:  export notice, request enter guest name.
+ Imported: perform the following steps
Total = 0
If (cạo vôi) Total += 100.000
If ( tẩy trắng) Total += 1.200.000
If ( chụp hình răng) Total +=200000
Total += (số răng trám)*80000
Export amount to TextBox txtTotal

FPT University Collection and Edit


7/19/2021Created by X31
WindowsForm using C# 2020

Result:
1. If customer name is not entered: alert message box will arise

2. Screen after charging for guests

FPT University Collection and Edit


7/19/2021Created by X31
WindowsForm using C# 2020

EXERCISE 2
Windows Form Application – Basic

* Content:
Building an application to simulate the Security Panel device as follows:
A lab wants to set up a Security Panel outside the door. Only authorized individuals are
allowed to enter and each login they must enter the provided security code. The following
security code (aka access code) is considered valid and provided to the employee groups as
follows:
Value Group
1645 or 1689 Technicians
8345 Custodians
9998, 1006 – 1008 Scientist
Once you enter the access code, there are two states: granted or denied. All access
information will be displayed in an information box below the keypad. If access is granted, the date,
time, group (technician, custodian, scientist) will be displayed in the info box. If access is denied,
the date, time and "Access denied" information will be displayed in the box below. In addition, if a
user only clicks a security code number, it will display a notice of the date, time and "Restricted
Access". An illustration of the interface of the Security Panel application

FPT University Collection and Edit


7/19/2021Created by X31
WindowsForm using C# 2020

Guideline:
1. Design the Form as shown in Figure 1
a. Describe the controls on the form as shown in Figure 2:

Describe the controls on the form


Instructions on how to quickly design buttons on the form:
 First create a button template first, format the button according to the
specified pattern including font, size, color ...
 Then copy the newly created template button, then paste it into the
appropriate locations
 Align the appropriate position for the buttons.
 Modify the Text property of each button.
 Rename again the Name attribute for each button.
b. Set properties for TextBox txtSecurityCode:

FPT University Collection and Edit


7/19/2021Created by X31
WindowsForm using C# 2020

- PasswordChar of TextBox is “*”


- ReadOnly is True
2. The next section writes handling for buttons on the Form (students do it themselves ...)
Guideline:
- Create an event listener Click common buttons 0 - 9. Each time buttons 0-9 are pressed,
add this number to the end of txtSecurityCode.Text (Text property stores the current
code that the user is entering) ).
o How to create a generic event handler for buttons:
 Select all buttons to create a handler (in the case above, select buttons
with numbers 0-9.
 Then double click on the Click event, in the property window. This
allows the creation of a generic event handler for the selected buttons.
* Note: If students double click on each button, they will create their own handlers for
each button! (Be careful in the case of this lab)
- Create a Click event handler for the button (#), which is the login or enter function.
Use the switch case statement to check if the code entered by the user is in the
description list on the Access Code table, the Access codes are: {1645,1689, 8345, 9998,
1006, 1008}. Then save the login information to the listbox as prescribed:
o Logged in successfully: Access code is valid (belonging to 1 of 6 codes above)
 Save an item line: <Date> <Time> <Group name>
o Fail: Access code is different from the code in the description table
 Save an item line: <Date> <Time> Restricted Access!
- Create the click event handler for the button (C), this is the button with the Clear
function: delete the entered code.

FPT University Collection and Edit


7/19/2021Created by X31
WindowsForm using C# 2020

EXERCISE 3
Windows Form Application – Advanced

1. Create a System Login Form using the following form, then save it with the name
Dangnhap.vb:

Hình 1
Requirement:
- Click on Việt Radio Button, the interface is as shown in Figure 1. Click on Anh
Radio Button, the interface is as in Figure 2 below:

Hình 2
 Similarly: Click Radio Button VI, the interface is as shown in Figure 1. Click
on Radio Button EN, the interface is as in Figure 2.
- When the cursor is in the textbox, the textbox background is pink. In contrast, the
white background.

FPT University Collection and Edit


7/19/2021Created by X31
WindowsForm using C# 2020

- If the TextBox is empty, the * sign is red. Contrast the blue * sign.
- Click the RESET button (or LÀM MỚI) to set empty for the TextBox.
- Click on the EXIT (or THOÁT) button, a message will appear:

 If OK, exit the program. Clicking Cancel does not exit the program.
- When LOGIN (or ĐĂNG NHẬP) button is pressed:
+ Check if the TextBox has enough information?
+ If you enter Username as “Admin” or “admin” and Password as “123456”, a
window will appear (In item 2). 

2. Create the Form to perform the calculation according to the following form and save
it with the name Pheptinh.vb:

FPT University Collection and Edit


7/19/2021Created by X31
WindowsForm using C# 2020

Requirement:
- When the cursor is in the textbox, the textbox background is pink. In contrast, the
white background.
- If the TextBox is empty, the * sign is red. Contrast the blue * sign.
- Click the RESET button (or REFRESH) to delete the TextBox.
- After Enter a, Enter b, select the calculation and press the THỰC HIỆN button,
the result will display on the Kết quả TextBox.
- Clicking the Next button will display the message "Do you want to go to the next
article?". If Yes is selected, go to the next window (In item 3). If you select No,
the window will remain.
3. Create the following form and save it as a name Tuychon.vb:

FPT University Collection and Edit


7/19/2021Created by X31
WindowsForm using C# 2020

 Add the Next button. Click the Next button to go to the Form in section 4

Requirement:
- When the cursor is in the textbox, the textbox background is pink. In contrast, the
white background.
- If the TextBox is empty, the * sign is red. Contrast the blue * sign.
- Click the RESET button, set empty for the TextBox.
- Require:
+ Enter enough information on the TextBox.
+ Only numbers are allowed.
- After entering enough and correct information, select one of the calculation
options and click the OK button, the corresponding calculation results will show
in place of Label3.
4. Create the following form and save it as a name Random.vb:

FPT University Collection and Edit


7/19/2021Created by X31
WindowsForm using C# 2020

Requirement:
- Select or enter a number in NumericUpDown to select the number of students to
randomly select topics.
 Pressing the PLAY button will display a random number from 1 to the selected
number.

 Pressing the PLAY button will bring up another random number from 1 to 34,
different from the previous one. Until the selected number runs out, the dialog box is
displayed:
FPT University Collection and Edit
7/19/2021Created by X31
WindowsForm using C# 2020

FPT University Collection and Edit


7/19/2021Created by X31
WindowsForm using C# 2020

EXERCISE 4
Windows Form Application – Advanced

1. Create the following form and save it as a name StartUp.vb:

Requirement: Use the ProgressBar control to run the process, after a period of time then
automatically switches to another window (As in item 2).
2. Create the following form and save it as a name frmMain.vb:

FPT University Collection and Edit


7/19/2021Created by X31
WindowsForm using C# 2020

 Add the Lunar button under the Exit button. When you press the Lunar button will
switch to a new window (As in item 3).
Requirement:
- Clicking Exit will exit the program.
- Clicking on the options will display the corresponding Club Logo (Image may be
changed if not available).
Guideline: To display the image, we do the following
pic1.Image = My.Resources.logo1;
Inside:
+ pic1 is the name of the PictureBox control.
+ logo1 is the name of the image added in Resource.

3. Create the following form and save it as a name Lunar.vb:

Requirement:
- When the cursor is in the textbox, the textbox background is pink. In contrast, the
white background.
- Click the Exit button and exit this window. (Me.Close())
- Entering the Calendar Year and clicking the View button will display the
corresponding lunar year.
Guideline:
- Declare 2 array variables can and chi.
- In Load Form mode, initialize values for 2 global variables as follows:
chi[1] = "Thân";
chi[2] = "Dậu";
chi[3] = "Tuất";
chi[4] = "Hợi";
FPT University Collection and Edit
7/19/2021Created by X31
WindowsForm using C# 2020

chi[5] = "Tý";
chi[6] = "Sửu";
chi[7] = "Dần";
chi[8] = "Mão";
chi[9] = "Thìn";
chi[10] = "Tỵ";
chi[11] = "Ngọ";
chi[12] = "Mùi";
can[1] = "Canh";
can[2] = "Tân";
can[3] = "Nhâm";
can[4] = "Quý";
can[5] = "Giáp";
can[6] = "Ất";
can[7] = "Bính";
can[8] = "Đinh";
can[9] = "Mậu";
can[10] = "Kỷ";
- Procedure when clicking the View button:
Private void btnView_Click()
{
int v_chi, v_can;
String v_result;
v_chi = Int32.parse(txtDuong.Text) % 12;
v_can = Int32.parse (txtDuong.Text) % 10;
v_result = can[v_can + 1] & " " & chi[v_chi + 1];
txtAm.Text = v_result;
txtDuong.Focus();
}

FPT University Collection and Edit


7/19/2021Created by X31

You might also like