Activity 2 Visual Studio (1) CTV
Activity 2 Visual Studio (1) CTV
Question 1:
Create the simple application to implement an Aggregation Function-Average for the two subject’s
marks. When you submit the marks of the two-subject average should be displayed in given text
box.
1. On the start page of the visual studio 2019, you can create new project as below.
2. In the search box type Windows form App. Then, select Windows form App
3. Config your project as follow
• Name the application as you need. Ex: WinformApp1
Then Project will be created as follow
4. Click on the project and you can Add new forms for the project as follow
Then select new Item
As below you can design your form by dragging tools on the forms form the toolbox:
(Hope now you have some idea how to design windows application with practice in
previous lab sheet.)
6. Create new application and default form design as below with toolbox.
By practicing in previous activity now you know how to design form with tool box.
7. Next you name all control and add display text for buttons and labels and add other
features with property window.
8. After you compete the naming for all controls next right click on the form and select the
view Code.
• Now you can view form.cs. In form.cs you can initiate the variable as below.
• Declare variable and initialize the variable following below coding.
• Use access modifiers as privet (variable cannot access out of the form.cs).
• Do read only for the txtAverage (then textbox cannot edit)
9. Next you need to write event for the validation.
• Select the validating event under the focus menu in the property event.
• Next you can validate the text field as below.
Code for validating event
Here conditions have checked with If statement. Be practice if statement well with this
application.
Steps:
• Next you need to assign text box value to the related variable in if statement one.
• After that you need to check the result variable in another if statement.
• Same way checks the result further as need in if else and else statement
• finally assign the result you need to display on label according to average mark.
11. Finally run the application
• End of the activity, you have got some ideas about how to develop simple application
with functions, event, if statements with C# with visual studio.
• Please follow the above Steps further and rewrite different event using C# in visual
studio.