760 likes | 783 Views
About the Presentations. The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning of each presentation. You may customize the presentations to fit your class needs.
E N D
About the Presentations • The presentations cover the objectives found in the opening of each chapter. • All chapter objectives are listed in the beginning of each presentation. • You may customize the presentations to fit your class needs. • Some figures from the chapters are included. A complete set of images from the book can be found on the Instructor Resources disc.
Programming with Microsoft Visual Basic 2010 5th Edition Chapter One An Introduction to Visual Basic 2010
Previewing the Splash Screen Figure 1-1 Splash screen for the Country Charm Inn
Lesson A Objectives After studying Lesson A, you should be able to: • Start and customize Visual Studio 2010 or Visual Basic 2010 Express • Create a Visual Basic 2010 Windows application • Manage the windows in the IDE • Set the properties of an object • Restore a property to its default setting • Save a solution • Close and open an existing solution
The Splash Screen Application • In this chapter, you create a splash screen using Visual Basic 2010 • Visual Basic 2010 is available as: • A stand-alone product • Visual Basic 2010 Express • Part of Visual Studio 2010
The Splash Screen Application (cont’d.) • Starting Visual Studio 2010 or Visual Basic 2010 Express • Click Start and point to All Programs • Select one of two environments • Microsoft Visual Studio 2010 • Microsoft Visual Basic 2010 Express • Click Window on the menu bar • Click Reset WindowLayout • Click Yes at prompt to restore default layout • Can also select a different window layout • Using Tools, Settings, on the menu bar
The Splash Screen Application (cont’d.) Figure 1-2 Microsoft Visual Studio 2010 Professional startup screen
The Splash Screen Application (cont’d.) Figure 1-3 Microsoft Visual Basic 2010 Express startup screen
The Splash Screen Application (cont’d.) • Configure Visual Basic 2010 Express • Click Tools on menu bar, point to Settings, then Expert Settings • Click Tools on menu bar, then Options, and deselect Show all settings if necessary • Click Projects and Solutions node • Select options as shown in Figure 1-4 on following slide, then click OK
The Splash Screen Application (cont’d.) Figure 1-4 Options dialog box
The Splash Screen Application (cont’d.) • Splash screen is a Windows application • Has Windows user interface • Windows applications composed of solutions, projects, and files • Solution: container that stores application’s projects and files • Can contain several projects • Project: container storing associated files
The Splash Screen Application (cont’d.) • Creating a Windows application • Click File on menu bar, then click New Project • Click Visual Basic in the Installed Templates list • If using Visual Studio, expand Visual Basic node and then click Windows • Click Windows Forms Application • Change name to Splash Project • Click Browse button to open Project Location dialog box • Click VB2010\Chap01 folder • Click Select Folder to close dialog box
The Splash Screen Application (cont’d.) • Creating a Windows application (cont’d.) • If necessary, select Create directory for solution • In New Project dialog box • Change name to Splash Solution • Completed New Project dialog boxes shown in Figures 1-5 and 1-6 on following slides • Click OK
The Splash Screen Application (cont’d.) Figure 1-5 Completed New Project dialog box in Visual Studio 2010 Professional
The Splash Screen Application (cont’d.) Figure 1-6 Completed New Project dialog box in Visual Studio 2010 Professional
The Splash Screen Application (cont’d.) • Managing the Windows in the Integrated Development Environment (IDE) • To open a window • Click View on menu bar, click Properties Window • Or mouseover Solution Explorer tab if auto-hidden • To close a window • Use Close button on window’s title bar • To minimize window to tab • Click Auto Hide (push-pin) button on Solution Explorer window
The Splash Screen Application (cont’d.) Figure 1-8 Current status of the windows in the IDE
The Splash Screen Application (cont’d.) • The Windows Form Designer window • Used to create graphical user interface (GUI) Figure 1-9 Windows Form Designer Window
The Splash Screen Application (cont’d.) • Windows Form object (or Form) • Foundation for UI in a Windows application • Create UI by adding objects • Buttons • Text boxes • Title bar contains default caption • Also minimize, maximize, and close buttons
The Splash Screen Application (cont’d.) • The Solution Explorer window • Displays list of projects contained in current solution • And items contained in each project Figure 1-10 Solution Explorer window
The Splash Screen Application (cont’d.) • Source file • File containing program instructions (code) • Form file • Contains code associated with a form • First form’s code stored in Form1.vb • Second form’s code stored in Form2.vb • And so on
The Splash Screen Application (cont’d.) • 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
The Splash Screen Application (cont’d.) Figure 1-11 Properties window
The Splash Screen Application (cont’d.) • Using the Properties window to change a form file’s name • Click File Name in Properties list • Type Splash Form.vb • .vb extension identifies file as source file • Press Enter
The Splash Screen Application (cont’d.) Figure 1-12 Form file’s name shown in various locations
Properties of a Windows Form • To view form properties • Click the form in the designer window • Click Alphabetical button to list alphabetically • Class definition • Specifies attributes and behaviors • Namespace • Code defining group of classes • Dot member access operator • Specifies hierarchy of namespaces • Example: System.Windows.Forms.Form
Properties of a Windows Form (cont’d.) Figure 1-13 Properties window showing a partial listing of the form’s properties
Properties of a Windows Form (cont’d.) • Name property • Refers to object in code • Each object has unique name • Must begin with letter • Contains only letters, numbers, and underscores • Hungarian notation: Naming convention • First three characters represent object’s type • Remaining characters represent object’s purpose • Name uses camel case (for camel’s hump) • Example: frmCalculateTaxes
Properties of a Windows Form (cont’d.) • To change form’s name • Drag Properties window scroll box to top of vertical scroll bar • Click Name in Properties list • Type frmSplash and press Enter • Asterisk appears to indicate unsaved changes
Properties of a Windows Form (cont’d.) • Text property • Controls text displayed in form’s title bar • Also appears on application’s taskbar button • Default value is Form1 • Should always be changed to meaningful value • To set form’s Text property • Click Text in the Properties list • Type Country Charm Inn and press Enter
Properties of a Windows Form (cont’d.) • The StartPosition property • Determines form’s initial position on screen • Splash screen’s StartPosition • Typically appears in the middle of the screen • To center form on screen • Click StartPosition in Properties list • Then click list arrow in settings box • Click CenterScreen
Properties of a Windows Form (cont’d.) • Font property • Determines type, style, and size of the font used on the form • Font indicates general shape of characters • Size is measured in points • To set form’s Font property • Click Font in Properties list, and click ellipsis button in Settings box • Locate and click the desired font and size • Then click OK
Properties of a Windows Form (cont’d.) • Size a form by selecting it and dragging sizing handles • Or select object and press and hold Shift key as you press desired arrow key • Size property • Two numbers separated by comma and space • First number represents width in pixels • Second number represents height in pixels
Setting and Restoring a Property’s Value • BackColor property • Determines form’s background color • Set the value of a property using settings box in Properties list • To restore default value of a property • Right-click property name and click Reset
Setting and Restoring a Property’s Value (cont’d.) Figure 1-14 Status of the form in the IDE
Saving a Solution • Save solution at regular intervals • For example, every 10 minutes • Options for saving a solution • Click File on menu bar and then click Save All • Click Save All button on Standard toolbar
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 • Close Solution option vs. Close option • Close option just closes IDE designer window
Opening an Existing Solution • Only one solution can be open at any one time • Currently open solution closes before another opens • Names of solution files end with .sln • Opening an existing solution • Click File on menu bar and then click Open Project • Select appropriate solution file then click Open
Exiting Visual Studio 2010 or Visual Basic 2010 Express • Options to exit from Visual Studio or Visual Basic Express • Use Close button on title bar • Click File on the menu bar and then click Exit
Lesson A Summary • Start Visual Studio from Start button • Configure Visual Studio or Visual Basic Express • Create an application using File, 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, then Save All • To open existing solution, click File, then Open Project
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
Lesson B Objectives (cont’d.) • 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
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
The Toolbox Window (cont’d.) Figure 1-15 Toolbox window showing the purpose of the Label tool
The Label Tool • Label tool: Used to create label control • Label control: Displays text that cannot be edited at run time • 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 value and Y value
Figure 1-16 Label tool being dragged to the form Figure 1-17 Label control added to the form
Changing a Property for Multiple Controls • Control inherits the Font attribute of the form • May want to change from default values • To simultaneously modify similar controls • Click one control and then press and hold Ctrl key • Click other similar control(s) in form • Or click and drag to group controls • Set property value in Properties list
Changing a Property for Multiple Controls (cont’d.) Figure 1-18 Label controls selected on the form
Using the Format Menu • Format menu: Options to manipulate form 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
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