c# laboratory activity #2- working on c# radio buttons and checked box (1).pdf

March 3, 2019 | Author: russel enriquez | Category: Boolean Data Type, Software Engineering, Software Development, Technology, Computer Engineering
Share Embed Donate


Short Description

Download c# laboratory activity #2- working on c# radio buttons and checked box (1).pdf...

Description

 Activity #3 Working on C# Group Box, Radio Buttons & Check Box Objectives: 

After completing this Activity you you will be able to: Use Visual Studio to build simple Windows Forms applications. o Apply the use use Radio Buttons and Check Box in Application development. development. o o Use Conditional Statements in Manipulating the Event Controls of Radio Radio Buttons and Check Box.

Introduction:

Group Box. C# windows control that displays a frame around a group of controls with an optional caption.

Figure 3.1 Windows form with Group Box, Check Box and Radio Button

Radio Button. Allows distinct selection of several items. In Groups of Radio Buttons, only one can be selected (Checked). This gives an exclusive selection for variety of items.

Check Box. Functions almost the same with Radio Buttons except that using this controls you can allow multiple selections at once.

1

Working on Group Box:

Group Box has essential functions of groupings your controls together. It gives your form a much more organize controls. Just like other controls you can change the properties of your Group Box depending on your needs. But most of the times you only access and change the “Name” property and the “Text” property (caption) of this controls. Example Activity:

1. Locate the Groupbox control in the Toolbox on the left, under Containers (or search on all windows form tools box).

Figure 3.2 Groupbox on Visual Studio 2. Drag it to your form and resize it. Locate the Name Properties and change it to “CheckboxGroup ”. 3. Locate the Text Properties and change it to “Which Engineering Program do you like in TIP? ” 4. Add another Group box and drag it just at the side of your “CheckboxGroup “, name it “RadioButtonGroup ”. Working on Check Box:

5. Edit the Text property of the RadioButtonGroup to “ And  And your your year Level Level is? ” 6. Now, Add 8 Checkbox  – es and change the Text properties of each checkbox to Engineering Program Offered by TIP.

Figure 3.3 TIP Engineering Program

2

7. You may change the name properties if each checked box, but for this activity we will use the default name. Working on Radio Button:

8. Now add Radio Radio Button on the other Group and put the Year Level as Text property of each Radiobutton.

9. Again you may change the Name Properties of each these Radio Button, but for our activity we were going to use the default name.

Producing Output, Using Conditional Statements.

10. Radio Button and checkbox has a lot of Properties, Events and Methods that can be access depending on the needs of the applications. But to show the processing involved in the access of these following controls, we will add a button to be clicked. Once clicked, it will identify which Engineering Program in TIP you like the most and which Year Level you are. The program will do this by identifying which on the Check Boxes are selected and which on the radio buttons is selected. -To implement this we will be manipulating the “Checked ” Event of the Checkbox and Radio Buttons. Check Box Radio Button

Checked Properties Selected (Boolean: TRUE) Selected (Boolean: TRUE)

Checked Properties Not Selected (Boolean: False) Not Selected (Boolean: False)

In case of Check Box, if that certain checkbox is checked (selected) it returns a value of TRUE, otherwise it returns FALSE. This goes the same with Radio Buttons.

11. Add a button just like in Fig. 3.4. Change its Name Property to “btnExecute ” and Text property to “Execute ”. 3

Figure 3.4 Final Form 12. Add the following codes under click event of btnExecute //code to handle Check box String programLike, String  programLike, Year; programLike = "" ""; ; //Initialize with "" if (checkBox1.Checked) (checkBox1.Checked) //CheckBox1 is Checked or checkBox2.Checked == TRUE programLike = programLike + "Civil Engineering "; "; if (checkBox2.Checked) (checkBox2.Checked) programLike = programLike + "Chemical Engineering "; "; if (checkBox3.Checked) (checkBox3.Checked) programLike = programLike + "Computer Engineering "; "; if (checkBox4.Checked) (checkBox4.Checked) programLike = programLike + "Electrical Engineering "; "; if (checkBox5.Checked) (checkBox5.Checked) programLike = programLike + "Electronics Engineering "; "; if (checkBox6.Checked) (checkBox6.Checked) programLike = programLike + "Industrial Engineering "; "; if (checkBox7.Checked) (checkBox7.Checked) programLike = programLike + "Mechanical Engineering "; "; if (checkBox8.Checked) (checkBox8.Checked) programLike = programLike + "Marine Engineeringg "; "; //code to handle Radio Button if (radioButton1.Checked) (radioButton1.Checked) Year = "First year"; year"; else if (radioButton2.Checked) (radioButton2.Checked) Year = "Second year"; year"; else if (radioButton3.Checked) (radioButton3.Checked) Year = "Third year"; year"; else if (radioButton4.Checked) (radioButton4.Checked) Year = "Fourth year"; year"; else if (radioButton5.Checked) (radioButton5.Checked) Year = "Fifth year"; year"; else Year = "Not Specified"; Specified" ; MessageBox.Show( MessageBox .Show("You "You Like " + " + programLike + " and your Year Level is "  + Year,"Message" Year,"Message"); );

13. Run the code. Click Start button on visual Studio. 4

EXERCISES: Exercise 3.1. Create a C# Calculator that performs the selected operation on Radio buttons.

Exercise 3.2. Create a simple 5 Multiple Questions Exam that uses Checkbox for Choices. Choices must contain at least 2 correct answers for each question. When the Button “Check” is clicked it will check the answers for each question and compute the grade based on TIP grading system.

Exercise 3.3. Create a C# program that will ask the user with at least 4 questions about the attributes of a super hero and presents whose super hero he/she based on the answers in the 4 questions. You may change the subject. (E.g. from super heroes you may change it to, characters in DOTA, gods and goddesses, animals or objects). Use Radio Buttons and Checkbox in the design of your applications.

--------------------------------------------------------------------------------------------------------------------------------------Note on Exercises:  A.

B.

3.

Have this at the beginning of your your program as comment: 1. Name of programmer 2. Date performed 3. Instructor 4. Program Description Prepare a documentation w/ the ff: 1. Manual with front page 2. GUI and Name Properties Source Code

5

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF