Presentation is loading. Please wait.

Presentation is loading. Please wait.

VB Controls and Events Week 7: Picture Box, Image Box, Option, Check box, Mouse over, Frames, Shapes.

Similar presentations


Presentation on theme: "VB Controls and Events Week 7: Picture Box, Image Box, Option, Check box, Mouse over, Frames, Shapes."— Presentation transcript:

1 VB Controls and Events Week 7: Picture Box, Image Box, Option, Check box, Mouse over, Frames, Shapes

2 Controls PictureBox Label TextBox Frame CommandButton CheckBox
OptionButton ComboBox ListBox HScrollBar VScrollBar Timer DriveListBox DirListBox FileListBox Shape Line Image …

3 PictureBox and Image Both controls have "Picture" property which specifies an image file. Image is simpler (has fewer properties) Has Stretch property allowing it to be scaled PictureBox is more complex Picture show is actual size. If you want to scale it, use paint, and then display.

4 CheckBox CheckBox has a
Caption Value (True of False) The value can be examined in an if-then statement, and the program can perform different actions based on the value. The value can be set by the program, which will cause the check to appear or disappear.

5 Sample CheckBox Code Make a checkbox Set its caption Set its value
Double click it to write code Run it and see how it works CheckBox values are 1 if checked and 0 if not. Private Sub Check1_Click() If Check1.Value = 1 Then Form1.BackColor = vbBlue Else Form1.BackColor = vbGreen End If End Sub

6 Option Buttons Are always more than one, but one and only one of them can be on at any one time. Each option button has Caption Value (True for only one option, and False for all others) If you make one value True, others are automatically made False.

7 Sample Option Button Code
Make four Option Buttons Make the captions Freshman Sophomore Junior Senior and more Important: Think if the options cover all possibilities, and no two are possible at the same time. Senior or more is needed to cover 5th year students. Add the following code, run it and see what happens. Option values are True if the option is selected and false if not. Private Sub Option1_Click() PrintOptions End Sub Private Sub Option2_Click() Private Sub Option3_Click() Private Sub Option4_Click() Private Sub PrintOptions() Form1.Print Option1.Value;

8 Frame If there are several different sets of options, each set of options must be in a frame (which may be invisible if you prefer) Only one option button in a frame can be True (selected) at any one time. Make the frame first, and put options in it later. Frames can be used, even if you don't use option buttons. Frames are useful for looks, and for grouping controls.

9 Frame Sample Design Make two frames with
caption "Year" and caption "Major" In the first frame put four option buttons as before In second, put CS/CMPE, Math, Econ, Accounting, SS, Law Note that the second option box does not allow double majors. If this was a real program we would need to Either list all double majors as options Or make checkboxes for majors Run without code

10 Shape Put a shape control on the form It has properties of
FillColor FillStyle BorderColor BorderStyle BorderWidth Try changing these properties and see what happens. You can change these properties from your program as well.

11 Shape and Drawing Understand the difference between using shapes and drawing on the form. A shape can be moved (simply by changing its Top, Left properties), a drawing can not. A shape can be resized by changing its Width and Height properties. A shape can be recolored, or even reshaped!

12 More Events In the code window, click the top left drop-down box, and select Form Now click the top right drop-down box and see the options available. You can write a sub to respond whenever any of these "events" happens. We will write sample code to respond to "MouseMove", so select MouseMove from the right drop-down box.

13 Sample Event Design Make a shape Make a check box
Set Shape property to Circle Set FillStyle to Solid Set FillColor to Red Make a check box Set caption to "Push/Pull" Do as instructed in previous slide to get Sub Form_MouseMove(...) in your code window Now add the code of the next slide.

14 Sample Event Code Run the program, and check the checkbox.
Dim jump Private Sub Check1_Click() If Check1 = 1 Then jump = -8 Else jump = 8 End If End Sub Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If Shape1.Top > Y Then Shape1.Top = Shape1.Top + jump Shape1.Top = Shape1.Top - jump If Shape1.Left > X Then Shape1.Left = Shape1.Left + jump Shape1.Left = Shape1.Left - jump Run the program, and check the checkbox. Move the cursor a lot. Now uncheck the checkbox. Move the cursor some more.


Download ppt "VB Controls and Events Week 7: Picture Box, Image Box, Option, Check box, Mouse over, Frames, Shapes."

Similar presentations


Ads by Google