Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter One An Introduction to Visual Basic 2008.

Similar presentations


Presentation on theme: "Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter One An Introduction to Visual Basic 2008."— Presentation transcript:

1 Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter One An Introduction to Visual Basic 2008

2 Previewing the Splash Screen Programming with Microsoft Visual Basic 2008, Fourth Edition2 Figure 1-1: Splash screen for the Country Charm Inn

3 3Programming with Microsoft Visual Basic 2008, Fourth Edition Lesson A Objectives After studying Lesson A, you should be able to: Start and customize Visual Studio 2008 or Visual Basic 2008 Express Edition Create a Visual Basic 2008 Windows application Manage the windows in the IDE Set the properties of an object Restore a property to its default setting

4 4Programming with Microsoft Visual Basic 2008, Fourth Edition Lesson A Objectives (continued) Save a solution Close a solution Open an existing solution

5 5Programming with Microsoft Visual Basic 2008, Fourth Edition The Splash Screen Application In this chapter, you create a splash screen using Visual Basic 2008 Visual Basic 2008 is available as: –A stand-alone product Visual Basic 2008 Express Edition –Part of Visual Studio 2008

6 6Programming with Microsoft Visual Basic 2008, Fourth Edition The Splash Screen Application (continued) To start Visual Studio 2008 or Visual Basic 2008 Express Edition: –Click Start and point to All Programs –Select one of two environments: Microsoft Visual Studio 2008 Microsoft Visual Basic 2008 Express Edition –Click Window on the menu bar –Click Reset Window Layout –Click Yes at prompt to restore default layout –Click the Maximize button if necessary

7 User interface: The part of program that user sees and interacts with Windows applications are composed of solutions, projects, and files Solution: Container that stores project and files for an entire application Project: Container that stores files associated with the project Template: Pattern used to create solutions and projects Programming with Microsoft Visual Basic 2008, Fourth Edition7 The Splash Screen Application (continued)

8 Creating a Windows application –First, set options in Visual Studio: Click Tools on menu bar and then click Options Expand Projects and Solutions, click General, and then check these options: –Always show Error List if build finishes with errors –Always show solution –Save new projects when created Uncheck Show Output window when build starts Click OK to close Options dialog Programming with Microsoft Visual Basic 2008, Fourth Edition8 The Splash Screen Application (continued)

9 Programming with Microsoft Visual Basic 2008, Fourth Edition9 Figure 1-3: Options dialog box The Splash Screen Application (continued)

10 Creating a Windows application (continued) –Click File menu, and then click New Project –Expand Visual Basic node, and then click Windows –Click Windows Form Application in the installed templates section of the Templates list –Change the project name in the Name box –Click Browse button to select the folder where solution will be stored –Click OK Programming with Microsoft Visual Basic 2008, Fourth Edition10

11 Programming with Microsoft Visual Basic 2008, Fourth Edition11 Figure 1-4: Completed New Project dialog box The Splash Screen Application (continued)

12 Programming with Microsoft Visual Basic 2008, Fourth Edition12 Figure 1-5: Solution and Visual Basic project The Splash Screen Application (continued)

13 13Programming with Microsoft Visual Basic 2008, Fourth Edition Managing the Windows in the IDE IDE: Integrated Development Environment Options to show a window –Click View on menu bar, select a window –Hover mouse over tab (if auto-hidden) Options to close a window –Use Close button on title bar To minimize window to tab: –Click Auto Hide (push-pin) toggle button on title bar

14 14Programming with Microsoft Visual Basic 2008, Fourth Edition The Windows Form Designer Window Graphical user interface (GUI) –Visual representation of the application Windows Form Designer window –Area in which you create (or design) the GUI Windows Form object (or form) –Foundation for the user interface To provide user interaction, add objects to the form –Examples of interaction objects: buttons, text boxes

15 15Programming with Microsoft Visual Basic 2008, Fourth Edition Figure 1-7: Windows Form Designer window The Windows Form Designer Window (continued)

16 16Programming with Microsoft Visual Basic 2008, Fourth Edition The Solution Explorer Window Solution Explorer window –Displays list of projects contained in current solution –Displays the items contained in each project Source file: File containing program instructions Code: Program instructions Form file –Contains code underlying a Windows Form object –Has a file extension of.vb

17 17Programming with Microsoft Visual Basic 2008, Fourth Edition The Solution Explorer Window (continued) Figure 1-8: Solution Explorer window

18 18Programming with Microsoft Visual Basic 2008, Fourth Edition The Properties Window Properties: Attributes of object that determine its appearance and behavior Properties window: Lists object’s properties Object box: Contains name of selected object Properties list: Helps identify and access properties Settings box: Shows current values of properties

19 19Programming with Microsoft Visual Basic 2008, Fourth Edition The Properties Window (continued) Figure 1-9: Properties window showing the properties of the Form1.vb file object

20 The Properties Window (continued) Programming with Microsoft Visual Basic 2008, Fourth Edition20 Figure 1-10: Form file’s name shown in the designer, Solution Explorer, and Properties windows

21 21Programming with Microsoft Visual Basic 2008, Fourth Edition Properties of a Windows Form To display properties of Windows Form object: –Select the Form object in designer window Two ways to organize properties: –Categorized –Alphabetical Class definition: Specifies attributes and behaviors Namespace: Code defining group of classes Dot member access operator: Specifies hierarchy –Example: System.Windows.Forms.Form

22 Programming with Microsoft Visual Basic 2008, Fourth Edition22 Figure 1-11: Properties window showing a partial listing of the form’s properties Properties of a Windows Form (continued)

23 23Programming with Microsoft Visual Basic 2008, Fourth Edition Name Property Name property: Refers to object in code Form’s name must begin with letter –Can contain only letters, numbers, and underscore Hungarian notation: Naming convention –First three characters represent type of object –Remaining characters represent object’s purpose –Name is entered in camel case (for camel’s hump) –Example: frmCalculateTaxes

24 24Programming with Microsoft Visual Basic 2008, Fourth Edition The Text Property Application name should appear in window’s title bar –The title bar should display an appropriate name Text property –Controls caption in form’s title bar –Also appears on application’s taskbar button –Default caption is Form1

25 25Programming with Microsoft Visual Basic 2008, Fourth Edition The StartPosition Property Determines where form first appears on screen

26 26Programming with Microsoft Visual Basic 2008, Fourth Edition Font Property Determines type, style, and size of the font used on the form

27 27Programming with Microsoft Visual Basic 2008, Fourth Edition Size Property Controls the height and width of the object Measured in pixels by default Pixel: Unit picture element of screen image

28 28Programming with Microsoft Visual Basic 2008, Fourth Edition Setting and Restoring the Value of a Property BackColor property: Sets form background color Set the value of a property using settings box in Properties window To restore default value of a property: –Right-click property name and click Reset

29 Programming with Microsoft Visual Basic 2008, Fourth Edition29 Figure 1-12: Status of the form in the IDE Setting and Restoring the Value of a Property (continued)

30 30Programming with Microsoft Visual Basic 2008, Fourth Edition Saving a Solution Save solution at regular intervals –For example, every 10 minutes Options for saving solution include: –Click File on menu bar and then click Save All –Click Save All button on Standard toolbar –Select solution’s name in Solution Explorer window and then click Save button on Standard toolbar

31 31Programming with Microsoft Visual Basic 2008, Fourth Edition Saving a Solution (continued) To determine which file will be saved: –Any tab on designer tab with asterisk indicates unsaved file –Hover mouse on Save button

32 32Programming with Microsoft Visual Basic 2008, Fourth Edition Closing the Current Solution Click File on menu bar and then click Close Solution Impact of closing current solution: –All projects and files contained within are closed Unsaved changes trigger warning prompt –You are given another chance to save your work

33 33Programming with Microsoft Visual Basic 2008, Fourth Edition Opening an Existing Solution Options to open an existing solution –Click File on menu bar and then click Open Solution –Select appropriate solution file –Or, double-click solution file on hard drive (.sln extension) Only one solution can be open at any one time –Currently open solution closes before another opens

34 34Programming with Microsoft Visual Basic 2008, Fourth Edition Exiting Visual Studio 2008 or Visual Basic 2008 Express Edition Options to exit from Visual Studio: –Use Close button on application window’s title bar –Click File on the menu bar and then click Exit

35 35Programming with Microsoft Visual Basic 2008, Fourth Edition Lesson A Summary Start Visual Studio from Start button To create solution, click File on menu bar and then click New Project Property values are set in Properties window of selected object Form’s Text property displays caption in title bar To save solution, click File on menu bar and then click Save All To open existing solution, click File on the menu bar, click Open, and then click Project/Solution

36 Lesson B Objectives After studying Lesson B, you should be able to: Add a control to a form Set the properties of a label, picture box, and button control Select multiple controls Center controls on the form Open the Project Designer window Programming with Microsoft Visual Basic 2008, Fourth Edition36

37 37Programming with Microsoft Visual Basic 2008, Fourth Edition Lesson B Objectives (continued) Start and end an application Enter code in the Code Editor window Terminate an application using the Me.Close() instruction Run the project’s executable file

38 The Toolbox Window Class: Pattern from which object is created Object: Instance with behaviors and attributes Toolbox window (or toolbox) –Contains tools for designing user interface –Each tool represents class –Controls are instantiated using tools from toolbox Controls: GUI objects that appear on a form Programming with Microsoft Visual Basic 2008, Fourth Edition38

39 39Programming with Microsoft Visual Basic 2008, Fourth Edition The Toolbox Window (continued) Figure 1-13: Box describing the purpose of the ListBox tool

40 The Label Tool Label tool: Used to create label control Label control: Displays text that cannot be edited at runtime Name property: Unique name for control Text property –Specifies value that appears in label control Location property –Specifies location of control on form –Includes X property and Y property Programming with Microsoft Visual Basic 2008, Fourth Edition40

41 41Programming with Microsoft Visual Basic 2008, Fourth Edition The Label Tool (continued) Figure 1-15: Label control added to the form

42 Changing the Property For More Than One Control At a Time To simultaneously modify similar controls: –Click one control and then press and hold Ctrl key –Click other similar control(s) in form –Set property value in Properties window Some properties are common to many controls, including: –Font property: Determines font type, style, size of the font Programming with Microsoft Visual Basic 2008, Fourth Edition42

43 Changing the Property For More Than One Control At a Time (continued) Programming with Microsoft Visual Basic 2008, Fourth Edition43 Figure 1-16: Label controls selected on the form

44 Using the Format Menu Format menu: Options to manipulate multiple selected controls –Align: Aligns selected controls by left, right, top, or bottom borders –Make Same Size: Makes width and/or height of selected controls uniform –Center in Form: Centers one or more controls Select as first control the one whose size or location you want to match –Called reference control Programming with Microsoft Visual Basic 2008, Fourth Edition44

45 The PictureBox Tool PictureBox tool: Creates picture box control Picture box control: Displays image on form Task box: Lists tasks associated with picture box Use task box to import image into project Project’s resource file contains imported images SizeMode property: Specifies if PictureBox or image itself should be resized to match other Programming with Microsoft Visual Basic 2008, Fourth Edition45

46 46Programming with Microsoft Visual Basic 2008, Fourth Edition The PictureBox Tool (continued) Figure 1-17: Task list for a picture box control

47 47Programming with Microsoft Visual Basic 2008, Fourth Edition Figure 1-18: Completed Select Resource dialog box The PictureBox Tool (continued)

48 Programming with Microsoft Visual Basic 2008, Fourth Edition48 Figure 1-19: Image shown in the picture box control The PictureBox Tool (continued)

49 The Button Tool Button tool: Used to create button control Button control: Used to perform action when clicked Common means of exiting a Windows application –Exit option on File menu –Exit button Programming with Microsoft Visual Basic 2008, Fourth Edition49

50 Starting and Ending an Application Startup form: Displays when application is first started Project Designer: Specifies startup form or executable code to be run –Right-click My Project in Solution Explorer and then click Open –Or, click Project on menu and then click Properties Application tab: Specify startup form Programming with Microsoft Visual Basic 2008, Fourth Edition50

51 51Programming with Microsoft Visual Basic 2008, Fourth Edition Figure 1-20: Application pane in the Project Designer window Starting and Ending an Application (continued)

52 Executable file: File that can be run outside of the IDE –File name ends with.exe Two ways to start application in IDE: –Click Debug on menu bar and then click Start Debugging –Press F5 key Application started from IDE runs in debug mode Programming with Microsoft Visual Basic 2008, Fourth Edition52

53 53Programming with Microsoft Visual Basic 2008, Fourth Edition Figure 1-21: Result of starting the copyright screen application Starting and Ending an Application (continued)

54 Writing Visual Basic 2008 Code Event: User action such as double-clicking Event procedure: Set of program instructions that are processed when event occurs Code Editor window –Provides templates for creating event procedures –Procedure header: First line in code template –Procedure footer: Last line in code template To open Code Editor window: –Right-click form and then click View Code Programming with Microsoft Visual Basic 2008, Fourth Edition54

55 55Programming with Microsoft Visual Basic 2008, Fourth Edition Writing Visual Basic 2008 Code (continued) Figure 1-22: Code Editor window opened in the IDE

56 Writing Visual Basic 2008 Code (continued) You can collapse or expand a region of code in the Code Editor window –Click minus box to collapse code –Click plus box to expand code Programming with Microsoft Visual Basic 2008, Fourth Edition56 Figure 1-23: Code collapsed in the Code Editor window

57 Writing Visual Basic 2008 Code (continued) Class Name list box: Lists names of objects (controls) on form Method Name list box: Lists appropriate events for selected object To select a control’s event in code editor window: –Select class name first and then select method name Syntax: Rules of programming language Programming with Microsoft Visual Basic 2008, Fourth Edition57

58 Writing Visual Basic 2008 Code (continued) Procedure header: First line in code template for event procedure Procedure footer: Last line in code template for event procedure Keyword: Predefined word in programming language that has special meaning –Are color-coded in IDE Programming with Microsoft Visual Basic 2008, Fourth Edition58

59 Writing Visual Basic 2008 Code (continued) Sub procedure: a block of code that performs a specific task Keywords in a sub procedure block: –Sub: starts a sub procedure –Private: restricts the use of the procedure to the form where it appears –End Sub: indicates the end of a sub procedure Event sub procedure names include the object name and the event name –Example: btnExit_Click Programming with Microsoft Visual Basic 2008, Fourth Edition59

60 The Me.Close() Instruction Method: Predefined Visual Basic procedure –Can be called (or invoked) when needed Me.Close() method: Causes current form to close –If it is only form in application, the application terminates IntelliSense feature: Provides appropriate selections as pop-up lists –Type first few letters of choice –Then use arrow keys to select an item in list Programming with Microsoft Visual Basic 2008, Fourth Edition60

61 The Me.Close() Instruction (continued) Programming with Microsoft Visual Basic 2008, Fourth Edition61 Figure 1-25: List displayed by the IntelliSense feature

62 62Programming with Microsoft Visual Basic 2008, Fourth Edition The Me.Close() Instruction (continued) Figure 1-26: Completed Click event procedure for the btnExit control

63 Lesson B Summary To add a control to a form, use tool from toolbox Use Label control for text that user cannot edit Use PictureBox control to display image Use Button control to cause action to occur Project Designer window: Used to change name of startup form and/or executable file To start and stop an application in IDE, use the Debug menu choice Programming with Microsoft Visual Basic 2008, Fourth Edition63

64 Lesson B Summary (continued) Code Editor window: Used to display, write, and edit procedures Me.Close() method: Closes the current form at runtime To run an executable file from IDE, use Debug menu To run an executable file outside IDE, browse to.exe file and double-click it Programming with Microsoft Visual Basic 2008, Fourth Edition64

65 Lesson C Objectives After studying Lesson C, you should be able to: Set the properties of a timer control Delete a control from the form Delete code from the Code Editor window Code the timer control’s Tick event procedure Remove and/or disable the form’s Minimize, Maximize, and Close buttons Prevent the user from sizing a form Print the project’s code Programming with Microsoft Visual Basic 2008, Fourth Edition65

66 Using the Timer Tool Splash screens typically close automatically –Do not usually contain Exit button –Timer control removes splash screen Timer tool: Used to create a timer control Timer control –Used to process code at regular time intervals –Does not appear on the user interface at runtime Interval property: Specified in milliseconds Enabled property: Allows timer to run if set to True Programming with Microsoft Visual Basic 2008, Fourth Edition66

67 Using the Timer Tool (continued) Tick event: –Occurs each time an interval has elapsed –Condition: Timer must be running (enabled) Add code into Tick event procedure –Code will be run when Tick event occurs Component tray –Special area below form design area in IDE –Stores controls not visible in user interface at runtime Programming with Microsoft Visual Basic 2008, Fourth Edition67

68 68Programming with Microsoft Visual Basic 2008, Fourth Edition Figure 1-29: Timer control placed in the component tray Using the Timer Tool (continued)

69 69Programming with Microsoft Visual Basic 2008, Fourth Edition Setting the FormBorderStyle Property FormBorderStyle property –Determines the border style of a form Some settings and their descriptions –Sizable: Allows user to change form’s size by dragging its borders at runtime –FixedSingle: Fixed, thin border line –None: No border

70 The MinimizeBox, MaximizeBox, and ControlBox Properties MinimizeBox property: Determines whether Minimize button appears on form’s title bar MaximizeBox property: Determines whether Maximize button appears on form’s title bar ControlBox property: Determines whether title bar elements (icons/buttons) appear on form Splash screens typically do not contain title bar –To remove title bar, delete contents of form’s Text property Programming with Microsoft Visual Basic 2008, Fourth Edition70

71 71Programming with Microsoft Visual Basic 2008, Fourth Edition Figure 1-31: Completed splash screen The MinimizeBox, MaximizeBox, and ControlBox Properties (continued)

72 72Programming with Microsoft Visual Basic 2008, Fourth Edition Printing Your Code You can print a copy of code entered in Code Editor window –Helps you understand and maintain application To print code: –Code editor window must be active (current) window Print options: –Hide collapsed regions –Include line numbers

73 Programming with Microsoft Visual Basic 2008, Fourth Edition73 Figure 1-32: Print dialog box Printing Your Code (continued)

74 Lesson C Summary Timer control: Processes code at specified intervals Use form’s MinimizeBox and MaximizeBox properties to enable or disable Minimize and Maximize buttons on form Form’s ControlBox property: Determines whether icon and control buttons will appear in title bar Form’s BorderStyle property: Determines if form will be sizable at runtime Print Visual Basic code with Code Editor window open Programming with Microsoft Visual Basic 2008, Fourth Edition74


Download ppt "Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter One An Introduction to Visual Basic 2008."

Similar presentations


Ads by Google