Presentation is loading. Please wait.

Presentation is loading. Please wait.

Items, Group Boxes, Check Boxes & Radio Buttons

Similar presentations


Presentation on theme: "Items, Group Boxes, Check Boxes & Radio Buttons"— Presentation transcript:

1 Items, Group Boxes, Check Boxes & Radio Buttons
Computer Science Items, Group Boxes, Check Boxes & Radio Buttons

2 Icons Using the Icon property of the form, you can change this displayed icon to something a little flashier.

3 TASK: Create your own Icon
Do this using Icon Edit 32x32 pixels are 8 times as large You can draw single points, lines, open rectangles and ovals, and filled rectangles and ovals. Once completed, the icon file can be saved for attaching to a form. Once you have finished your icon, save it. Click File, then Save. Icon files are special graphics files saved with an ico extension. Teacher resource Sandwich.ico which is in the IconEdit folder.

4 Assigning Icons to Forms
Start Visual Basic Express and start a new project. A blank form should appear. Go to the properties window and click on the Icon property. An ellipsis (...) button appears. Click that button and a window that allows selection of icon files will appear.

5 Group Box Control A group box is simply a control that can hold other controls. Group boxes provide a way to separate and group controls and have an overall enable/disable feature. This means if you disable the group box, all controls in the group box are also disabled. The group box has no events, just properties. In Toolbox: On Form (default properties):

6 Placing Controls in a Group Box
Place controls directly in the group box using any of the usual methods. Draw controls outside the group box and drag them in. Copy and paste controls into the group box (prior to the paste operation, make sure the group box is selected).

7 TASK: Group Boxes Start a new project. Put a group box on the form and resize it so it is fairly large. Select the button control in the Visual Basic Express toolbox. Drag the control until it is over the group box. Drop the control in the group box. Put a second button in the group box. Put a numeric updown control in the group box. Notice how the controls are associated with the group box. Run the project. Notice you can click on the buttons and use the numeric updown control. Stop the project.

8 TASK: Group Boxes Set the group box Enabled property to False. Run the project again. Notice the group box title (set by the Text property) is grayed and all of the controls on the group box are now disabled - you can’t click the buttons or updown control. Hence, by simply setting one Enabled property (that of the group box), we can enable or disable a number of individual controls. Stop the project. Reset the group box Enabled property to True. Set the Visible property to False (will remain visible in design mode). Run the project. The group box and all its controls will not appear. You can use the Visible property of the group box control to hide (or make appear) some set of controls (if your project requires such a step). Stop the project.

9 TASK: Group Boxes Change the Visible property back to True. Place a label control in the group box. Change the BackColor property of the group box. Notice the background color of the label control takes on the same value, while the button controls are unaffected. Recall this is because the group box is a ‘container’ control. Sometimes, this sharing of properties is a nice benefit, especially with label controls. Other times, it is an annoyance. If you don’t want controls to share properties (BackColor, ForeColor, Font) with the group box, you must change the properties you don’t like individually.

10 Check Box Control A check box provides a way to make choices from a group of things. When a check box is selected, a check appears in the box. Toolbox: On Form (default properties):

11 TASK: Check Boxes Start a new project. Draw a group box.
Place three or four check boxes in the group box Move the group box to make sure the check boxes are in the group box. Run the project. Click the check boxes and see how the check marks appear and disappear. Notice you can choose as many, or as few, boxes as you like. In code, we would examine each check box’s Checked property to determine which boxes are selected. Stop the project. Change the BackColor of the group box. Notice the check box controls’ background color changes to match.

12 Radio Button Control A radio button provides a way to make a “mutually-exclusive” choice from a group of things. Radio buttons always work in groups and each group must be in a separate group box control. In Toolbox: On Form (default properties):

13 TASK: Radio Buttons Start a new project. Draw a group box.
Place three or four radio buttons in the group box. Set one of the buttons Checked property to True. Run the project. Notice one button has a filled circle. Click another radio button. That button will be filled while the previously filled button will no longer be filled. Keep clicking buttons to get the idea of how they work. Change the group box BackColor property and notice all the ‘contained’ radio buttons also change background color.

14 TASK: Radio Buttons Draw another group box on the form. Put two or three radio buttons in that group box and set one button’s Checked property to True. As always, make sure the buttons are properly placed in the group box. Run the project. Change the selected button in this second group. Notice changing this group of radio buttons has no effect on the earlier group. Remember that radio buttons in one group box do not affect radio buttons in another.

15 Decisions - Select Case
The If/End If structure is a way of letting Visual Basic Express make decisions using comparison operators and logical operators. We could implement such a logic using If, ElseIf, and End If statements. As an example, say we want to do different things if the variable A is 0, 1, 2, 3, 4, or 5 The BASIC code, using an If/End If structure, to do this is: If A = 0 Then [BASIC code for A = 0] ElseIf A = 1 Then [BASIC code for A = 1] ElseIf A = 2 Then [BASIC code for A = 2] ElseIf A = 3 Then [BASIC code for A = 3] ElseIf A = 4 Then [BASIC code for A = 4] ElseIf A = 5 Then [BASIC code for A = 5] End If This code will work but there is a lot of repetition. It is also difficult to make simple changes to values A might have. BASIC offers another way to make decisions such as this.

16 Decisions - Select Case
Select Case TestExpression Case Comparison1 [BASIC code to execute if Comparison1 matches TestExpression] Case Comparison2 [BASIC code to execute if Comparison2 matches TestExpression] Case Comparison3 [BASIC code to execute if Comparison3 matches TestExpression] Case Comparison4 [BASIC code to execute if Comparison4 matches TestExpression] Case Else [BASIC code to execute if no comparison matches TestExpression] End Select The Select Case statement is used to make decisions based on the value of a single variable or expression. A typical structure for the Select Case statement is: The TestExpression is any BASIC expression. Select Case goes through the list of Case statements, top to bottom, until it finds a Case where TestExpression matches the listed Case comparison. The BASIC statements associated with that particular Case are then executed and program execution moves to the first line after the End Select statement. If no match is found, the statements associated with Case Else are executed. If there is no Case Else and no match is found, none of the statements in the Select Case/End Select structure are executed. There is no limit to the number of Case statements allowed. What do the comparisons in the Case statements look like?

17 Decisions - Select Case
The simplest comparison is just a single value against which TestExpression is tested for equality. For example, Case 6 would check to see if the TestExpression is equal to 6. You can use the To keyword to check against a range of values. For example, Case 6 To 14 checks to see if TestExpression is between 6 and 14 (inclusive). The Is keyword can be used with a comparison operator to make a logical comparison. For example, Case Is > 8 would check to see if TestExpression is greater than 8. Multiple comparison expressions can be used in one Case statement using commas as separators. The commas act like the Or logical operator. To see if TestExpression is between 2 and 4, between 8 and 12, or less than 2, we would use the Case statement: Case 2 To 4, 8 To 12, Is < 2 Whenever you are making multiple checks on a value of an expression, consider the Select Case statement instead of the If statement.

18 Decisions - Select Case
As mentioned, you can have as many Case statements as you want. But, like the If/End If structure, only one section of BASIC code in a Select Case structure will be executed. This means that once BASIC has found a Case comparison that matches the Select Case expression, it will execute that section of code then leave the structure and execute the first line of code following the End Select statement. The rule for Select Case structures is: only the statements associated with the first matching Case will be executed.

19 Difference between IF and SELECT CASE
If MyGuess = TheNumber Then [BASIC code for correct answer] ElseIf Math.Abs(MyGuess - TheNumber) <= 2 Then [BASIC code when burning up - within 2 of correct answer] ElseIf Math.Abs(MyGuess - TheNumber) <= 5 Then [BASIC code when hot - within 5 of correct answer] ElseIf Math.Abs(MyGuess - TheNumber) <= 15 Then [BASIC code when warm - within 15 of correct answer] ElseIf Math.Abs(MyGuess - TheNumber) <= 25 Then [BASIC code when cold - within 25 of correct answer] Else [BASIC code when freezing - more than 25 away] End If

20 Difference between IF and SELECT CASE
Select Case Math.Abs(MyGuess - TheNumber) Case 0 [BASIC code for correct answer] Case Is <= 2 [BASIC code when burning up - within 2 of correct answer] Case Is <= 5 [BASIC code when hot - within 5 of correct answer] Case Is <= 15 [BASIC code when warm - within 15 of correct answer] Case Is <= 25 [BASIC code when cold - within 25 of correct answer] Case Else [BASIC code when freezing - more than 25 away] End Select


Download ppt "Items, Group Boxes, Check Boxes & Radio Buttons"

Similar presentations


Ads by Google