clearly visual basic: programming with visual basic 2008 chapter 4 i need a tour guide

34
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide

Upload: walter-gordon

Post on 12-Jan-2016

222 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide

Clearly Visual Basic: Programming with Visual Basic 2008

Chapter 4 I Need a Tour Guide

Page 2: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide

Clearly Visual Basic: Programming with Visual Basic 2008

Objectives

• Create a Visual Basic 2008 Windows application

• Use the Label and PictureBox tools to add a control to a form

• Set the properties of an object

• Save a solution

2

Page 3: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide

Clearly Visual Basic: Programming with Visual Basic 2008

Objectives (continued)

• Size and align objects using the Format menu

• Lock the controls on a form

• Start and end an application

• Close and open an existing solution

3

Page 4: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide

Clearly Visual Basic: Programming with Visual Basic 2008

OK, the Algorithm is Correct. What’s Next?

• User interface – What appears on the screen and with which you

interact while using a program

• Integrated development environment (IDE) – Contains the tools and features you need to create,

run, and test your programs

4

Page 5: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide

Clearly Visual Basic: Programming with Visual Basic 2008 5

Page 6: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide

Clearly Visual Basic: Programming with Visual Basic 2008

Creating a Visual Basic Windows Application

• Windows applications in Visual Basic – Composed of solutions, projects, and files

• Solution – Can contain several projects

• Project– Container that stores files associated with project

6

Page 7: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide

Clearly Visual Basic: Programming with Visual Basic 2008 7

My Wizard Quick StartCreate a folder in C:\users\yourName\  called VBBefore you create your first application click on TOOLS- OPTIONSGo to Projects and solutionsVisual Studio Project Locations:  C:\users\you\VB                   User Templates:    C:\users\you\VB                   Item Templates:    C:\users\you\VB                   Check the following:                       Always show Error list Item in Solution Explorer                       Track Active Item in Solution Explorer                       Always show Solution                       Save New Projects when created                        Create a new VB Window ApplicationName it My Wizard ProjectPin the Control Toolbar and Properties Window (Properties window is Alphabetic)Name the Form1 Text property:  Wizard Application

Page 8: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide

Clearly Visual Basic: Programming with Visual Basic 2008 8

Page 9: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide

Clearly Visual Basic: Programming with Visual Basic 2008 9

Page 10: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide

Clearly Visual Basic: Programming with Visual Basic 2008

So Many Windows

• You will find it easier to work in the IDE if: – You either close or auto-hide the windows you are not

currently using

• Auto Hide button– Toggle button: clicking it once activates it; clicking it

again deactivates it

10

Page 11: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide

Clearly Visual Basic: Programming with Visual Basic 2008 11

Page 12: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide

Clearly Visual Basic: Programming with Visual Basic 2008

Creating the User Interface

• Windows Form Designer window – Where you create (or design) your application’s user

interface

• Form – The foundation for the user interface in a Windows

application– Automatically includes a title bar that contains a

default caption

12

Page 13: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide

Clearly Visual Basic: Programming with Visual Basic 2008 13

Page 14: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide

Clearly Visual Basic: Programming with Visual Basic 2008

Creating the User Interface (continued)

• Controls– Objects added to a form

• Picture box – Displays an image on a form

• Label controls– Display text that user is not allowed to edit while

application is running

14

Page 15: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide

Clearly Visual Basic: Programming with Visual Basic 2008 15

Page 16: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide

Clearly Visual Basic: Programming with Visual Basic 2008

Save, Save, Save• Good practice

– Save current solution every 10 or 15 minutes

• To save a solution – Click on File on the menu bar, then click Save All

• Mini Quiz 1. A ____ control displays text that the user is NOT allowed to edit while an application is running 2. The _________ contains the toos you use to add objects to a form 3. GUI stands for _____________________

16

Page 17: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide

Clearly Visual Basic: Programming with Visual Basic 2008

Whose Property Is It?

• Properties– Determine object’s appearance and behavior

• Name and current value of each property – Appear in the Properties window when the object is

selected

• Select the Form– Change the Text Property to Wizard Application– Change StartPosition to Center Screen– Change font to Segoe 9 Point

17

Page 18: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide

Clearly Visual Basic: Programming with Visual Basic 2008 18

Change the Properties Window to Alphabetical

Page 19: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide

Clearly Visual Basic: Programming with Visual Basic 2008

Whose Property Is It? (continued)

• Exercises– Change the values assigned to some of the form’s

properties– Change two properties of each label control– Change two properties of each picture box

19

Page 20: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide

Clearly Visual Basic: Programming with Visual Basic 2008

Using the Format Menu

• Format menu– Provides several options for manipulating controls in

the interface

• Exercises– Make the PictureBox1 control the same size as the

PictureBox2 control– Align the top borders of the two picture boxes– Click the task box and Choose Image

find the images and import them to the screen– Wizard 1 –Size Mode = Stretch– Wizard 2- Size Mode = Auto Size

20

Page 21: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide

Clearly Visual Basic: Programming with Visual Basic 2008 21

Change Label1’s text property to Wizard 1 and Label2’s Text Property to Wizard 2Change the Location property of Wizard 1 to 40,212

and the location property of Wizard 2 to 175, 212

Page 22: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide

Clearly Visual Basic: Programming with Visual Basic 2008

Lock Them Down

• Locking the controls– Prevents them from being moved inadvertently as you

work in the IDE

• Unlock and then lock the controls

• Right Click the Form and Choose Lock Controls

22

Page 23: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide

Clearly Visual Basic: Programming with Visual Basic 2008 23

Page 24: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide

Clearly Visual Basic: Programming with Visual Basic 2008

OK, Let’s See the Interface in Action

• You can start an application by:– Clicking Debug on the menu bar and then clicking

Start Debugging

or– You can simply press the F5 key on your keyboard

24

Page 25: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide

Clearly Visual Basic: Programming with Visual Basic 2008 25

Page 26: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide

Clearly Visual Basic: Programming with Visual Basic 2008

Closing the Current Solution

• To close a solution – Use the Close Solution option on the File menu

• When you close a solution– All projects and files contained in the solution are also

closed

26

Page 27: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide

Clearly Visual Basic: Programming with Visual Basic 2008

Opening an Existing Solution

• To open an existing solution– Use the File menu or the Start Page

• If a solution is already open in the IDE– It is closed before another solution is opened

27

Page 28: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide

Clearly Visual Basic: Programming with Visual Basic 2008

Exiting Visual Studio

• To exit Visual Studio– Use either the Close button on its title bar

or – The Exit option on the File menu

28

Page 29: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide

Clearly Visual Basic: Programming with Visual Basic 2008

Summary

• Creating the user interface– Fourth step in the problem-solving process

• Windows applications in Visual Basic – Composed of solutions, projects, and files

• Label controls – Display text that user is not allowed to edit while an

application is running

29

Page 30: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide

Clearly Visual Basic: Programming with Visual Basic 2008

Summary (continued)

• Picture boxes – Used to display images on a form

• Good practice to save a solution every 10 or 15 minutes

• Form’s StartPosition property – Specifies the position of the form when it first appears

on the screen

30

Page 31: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide

Clearly Visual Basic: Programming with Visual Basic 2008

Summary (continued)

• Font property – Determines the type, style, and size of font used to

display text on the form

• Picture box control’s Image property – Specifies name of file containing the image to display

• Good practice to: – Lock the controls in place on the form

31

Page 32: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide

32

Mini Quiz1.The name of the image file assigned to a picture box control is stored in the control’s __________ property2.The value assigned to a label control’s ______ property appears in side the Control3.A control’s Location Property specifies the location of the control’s _________corner on the form4.How did you make the two picture boxes the same size?5.To start a VB application, click Debug, and then click _________________ Actually the best way to start a VB program is to press the F5 KEYREVIEW QUESTIONS1.A Windows form automatically contains:a. Close, Maximize, Minimize buttons b. a default caption c. a title bard. all of the above2.To display the text “ABC Company” at the top of your interface, use a:a. Form b. Label C. Picture Box D. None of theses3.You use the ______ window to set characteristics of an objecta. Characteristics b. Designer c. Object d. Properties4.The ______ property determines the position of a form when it is rana. StartPosition b. Location c. StartLocation d. InitialPosition5.When aligning 2 objects, the first control selected is called the:a. initializer b. Positioning c. reference d. none of the these

Page 33: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide

Page 73- #5 Program the Picture Box

Clearly Visual Basic: Programming with Visual Basic 2008 33

Insert the Picture – Lightning_bolts.gif (downloaded earlier)Double click on Each button to Program themThe show button: Picturebox1.visible = trueThe Hide Button: Picturebox1.visible = FalseThe Exit Button Me.CloseSEE THE NEXT SLIDE

Page 34: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide

Clearly Visual Basic: Programming with Visual Basic 2008 34

Page 73-74 Project #5Double click on each Button: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click PictureBox1.Visible = True End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click PictureBox1.Visible = False End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Me.Close() End Sub