Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 1: An Introduction to Visual Basic 2005 Programming with Microsoft Visual Basic 2005, Third Edition.

Similar presentations


Presentation on theme: "Chapter 1: An Introduction to Visual Basic 2005 Programming with Microsoft Visual Basic 2005, Third Edition."— Presentation transcript:

1 Chapter 1: An Introduction to Visual Basic 2005 Programming with Microsoft Visual Basic 2005, Third Edition

2 2 Programming with Microsoft Visual Basic 2005, Third Edition An Introduction to Visual Basic 2005 Lesson A Objectives Start and customize Visual Studio 2005 or Visual Basic 2005 Express Edition Create a Visual Basic 2005 Windows-based application Manage the windows in the IDE Set the properties of an object Restore a property to its default setting

3 3 Programming with Microsoft Visual Basic 2005, Third Edition An Introduction to Visual Basic 2005 Lesson A Objectives (continued) Save a solution Close a solution Open an existing solution

4 4 Programming with Microsoft Visual Basic 2005, Third Edition Starting Visual Studio 2005 or Visual Basic 2005 Express Edition Click Start and point to All Programs Select one of two environments –Microsoft Visual Studio 2005 –Microsoft Visual Basic 2005 Express Edition Click Window on the menu bar Click Reset Window Layout Click Yes at prompt to restore default layout

5 5 Programming with Microsoft Visual Basic 2005, Third Edition Starting Visual Studio 2005 or Visual Basic 2005 Express Edition (continued) Figure 1-2: Microsoft Visual Basic 2005 startup screen

6 6 Programming with Microsoft Visual Basic 2005, Third Edition Starting Visual Studio 2005 or Visual Basic 2005 Express Edition (continued) Figure 1-4: Purpose of the windows included in the IDE

7 7 Programming with Microsoft Visual Basic 2005, Third Edition Creating the Copyright Screen Application Applications comprise solutions, projects, and files Solution: container storing projects and files Project: contains files for a part of the solution Template –Pattern used to create solutions and projects –Includes standard folders and files Windows presented are from Visual Studio 2005

8 8 Programming with Microsoft Visual Basic 2005, Third Edition Creating the Copyright Screen Application (continued) Figure 1-5: Illustration of a solution, project, and file

9 9 Programming with Microsoft Visual Basic 2005, Third Edition Creating the Copyright Screen Application (continued) Figure 1-8: Solution and Visual Basic project created in Visual Studio 2005

10 10 Programming with Microsoft Visual Basic 2005, Third Edition Managing the Windows in the IDE Options to show a window –Click View on the menu bar, select a window –Hover the mouse over the tab (if auto-hidden) Options to close a window –Use the Close button on the title bar How to minimize a window to a tab –Use Auto Hide (pushpin) button on the title bar

11 11 Programming with Microsoft Visual Basic 2005, Third 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 Form –Examples of interaction objects: buttons, text boxes

12 12 Programming with Microsoft Visual Basic 2005, Third Edition The Windows Form Designer Window (continued) Figure 1-11: Windows Form Designer window

13 13 Programming with Microsoft Visual Basic 2005, Third 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: a file containing program code Code: the program instructions Form file –Contains code underlying a Windows Form object –Has a file extension of.vb

14 14 Programming with Microsoft Visual Basic 2005, Third Edition The Properties Window Properties: attributes of an object Properties window: exposes object’s properties Object box: contains name of selected object Properties list: helps identify and access properties Settings box: shows current values of properties

15 15 Programming with Microsoft Visual Basic 2005, Third Edition The Properties Window (continued) Figure 1-13: Properties window showing the properties of the Form1.vb file object

16 16 Programming with Microsoft Visual Basic 2005, Third Edition Properties of the Windows Form Object Displaying properties of Windows Form object –Select Windows Form object in designer window Two ways to organize properties –Press Categorized or Alphabetical button Class definition: specifies attributes and behaviors Namespace: code defining a group of classes Dot member access operator: specifies hierarchy –Example: System.Windows.Forms.Form

17 17 Programming with Microsoft Visual Basic 2005, Third Edition Properties of the Windows Form Object (continued) Name property: refers to the object in code Hungarian notation naming convention –First three characters represent the type of object –Remaining characters represent object’s purpose –Name is entered in camel case (for camel’s hump) –Example: frmCalculateTaxes New naming convention –Indicate the form purpose and class –Form names are entered using Pascal case –Example: CopyrightForm

18 18 Programming with Microsoft Visual Basic 2005, Third Edition Properties of the Windows Form Object (continued) Two naming conventions for Windows applications –Name should appear in application window’s title bar –The title bar should display an appropriate name Text property –Controls the caption in the form’s title bar –Also appears on the application’s taskbar button –The default caption is Form1 StartPosition property –Determines where the form first appears on screen

19 19 Programming with Microsoft Visual Basic 2005, Third Edition Properties of the Windows Form Object (continued) Size property –Controls the height and width of the object –Measured in pixels by default Pixel: unit picture element of a screen image Set the value of a property using the settings box How to restore the default value of a property –Right-click the property name and select Reset BackColor property: sets the form background color

20 20 Programming with Microsoft Visual Basic 2005, Third Edition Saving a Solution Save a solution at regular intervals; e.g., 10 minutes Options for saving a solution –Select File on the menu bar, then Save All –Click the Save All button on the Standard toolbar –Select solution’s name in Solution Explorer window –Click the Save button on the Standard toolbar How to determine which file will be saved –Hover the mouse on the Save button

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

22 22 Programming with Microsoft Visual Basic 2005, Third Edition Opening an Existing Solution Options to open an existing solution –Go to File  Open Solution for dialog box –Select the appropriate solution file –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

23 23 Programming with Microsoft Visual Basic 2005, Third Edition Exiting Visual Studio 2005 or Visual Basic 2005 Express Edition Options to exit an application –Use Close button on application window’s title bar –Select File on the menu bar, then Exit

24 24 Programming with Microsoft Visual Basic 2005, Third Edition Summary – Lesson A To create a solution, select Tools on the menu bar, then Options, and then Projects and Solution Form’s Text property displays a caption in the title bar Property values are set in the Properties window of a selected object To save a solution, select File on the menu bar, then Save All To open an existing solution, select File on the menu bar, then Open, then Project/Solution

25 25 Programming with Microsoft Visual Basic 2005, Third Edition Working with Controls Lesson B Objectives 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

26 26 Programming with Microsoft Visual Basic 2005, Third Edition Working with Controls Lesson B Objectives (continued) Start and end an application Enter code in the Code Editor window Terminate an application using the Me.Close method

27 27 Programming with Microsoft Visual Basic 2005, Third Edition The Toolbox Window Class: pattern from which an object is created Object: instance with behaviors and attributes Toolbox window (or toolbox) –Contains tools for designing a user interface –Each tool represents a class –Controls are instantiated using tools from toolbox Controls: GUI objects that appear on a form

28 28 Programming with Microsoft Visual Basic 2005, Third Edition The Toolbox Window (continued) Figure 1-17: Box describing the purpose of the ListBox tool

29 29 Programming with Microsoft Visual Basic 2005, Third Edition Using the Label Tool Label tool: used to create a label control Label control –Displays text that cannot be edited at runtime Text property –Determines value that appears in the label control Location property –Determines location of the label control on the form –Includes the X property and the Y property

30 30 Programming with Microsoft Visual Basic 2005, Third Edition Using the Label Tool (continued) Figure 1-19: Label control added to the form

31 31 Programming with Microsoft Visual Basic 2005, Third Edition Changing the Property for More Than One Control at a Time How to simultaneously modify similar controls –Click one control, then press and hold the Ctrl key –Click the other similar control(s) in the form –Set the property value in the Properties window Font property: determines font type, style, size Font: the general shape of characters in text Point: a measure of font size (1/72 of an inch)

32 32 Programming with Microsoft Visual Basic 2005, Third Edition Changing the Property for More Than One Control at a Time (continued) Figure 1-20: Label controls selected on the form

33 33 Programming with Microsoft Visual Basic 2005, Third Edition Using the Format Menu Format menu: options to manipulate controls –Align: aligns by left, right, top, or bottom borders –Make Same Size: makes width and/or height uniform –Center in Form option: centers one or more controls

34 34 Programming with Microsoft Visual Basic 2005, Third Edition Using the PictureBox Tool PictureBox tool: creates a picture box control Picture box control: displays an image on a form Task box: lists tasks associated with a picture box Use the task box to import an image into a project Project’s resource file contains imported images

35 35 Programming with Microsoft Visual Basic 2005, Third Edition Using the PictureBox Tool (continued) Figure 1-23: Task list for a picture box control

36 36 Programming with Microsoft Visual Basic 2005, Third Edition Using the PictureBox Tool (continued) Figure 1-24: Completed Select Resource dialog box

37 37 Programming with Microsoft Visual Basic 2005, Third Edition Using the Button Tool Common means of exiting a Windows application –Exit option on a File menu –Exit button Button tool: used to create a button control Button control: reacts to a click event

38 38 Programming with Microsoft Visual Basic 2005, Third Edition Using the Button Tool (continued) Figure 1-26: Button control added to the form

39 39 Programming with Microsoft Visual Basic 2005, Third Edition Starting and Ending an Application Startup form: displays when application is started Project Designer: specifies startup form/executable Executable file: can be run outside of the IDE Two ways to start an application in the IDE –Select Debug on menu bar, then Start Debugging –Press the F5 key on the keyboard Application started in IDE runs in debug mode

40 40 Programming with Microsoft Visual Basic 2005, Third Edition Starting and Ending an Application (continued) Figure 1-28: Completed Copyright Project Designer window

41 41 Programming with Microsoft Visual Basic 2005, Third Edition Starting and Ending an Application (continued) Figure 1-29: Result of starting the copyright screen application

42 42 Programming with Microsoft Visual Basic 2005, Third Edition Writing Visual Basic 2005 Code Event: a user action such as double-clicking Event procedure: instructions handling an event Code Editor window –Provides templates for creating event procedures –Procedure header: first line in the code template –Procedure footer: last line in the code template Class Name list box: lists the names of objects Method Name list box: lists appropriate events

43 43 Programming with Microsoft Visual Basic 2005, Third Edition Writing Visual Basic 2005 Code (continued) Figure 1-32: xExitButton’s Click event procedure shown in the Code Editor window

44 44 Programming with Microsoft Visual Basic 2005, Third Edition Writing Visual Basic 2005 Code (continued) Sub procedure: code block performing a task Keyword: predefined word in a language –Sub : starts a sub procedure –Private: restricts procedure to class of definition –End Sub : indicates the end of a sub procedure Parameters: data passed to a called procedure

45 45 Programming with Microsoft Visual Basic 2005, Third Edition Writing Visual Basic 2005 Code (continued) Method –A predefined Visual Basic procedure –Called (or invoked) when needed Me.Close method: causes current form to close IntelliSense: provides appropriate selections Sequential processing: serial instruction execution Sequence structure: set of sequential instructions

46 46 Programming with Microsoft Visual Basic 2005, Third Edition Writing Visual Basic 2005 Code (continued) Figure 1-33: The IntelliSense feature displays a list of choices

47 47 Programming with Microsoft Visual Basic 2005, Third Edition Summary – Lesson B To add a control to a form, use a tool from the toolbox Some controls used: Label, PictureBox, Button Project Designer window: used to change the names of the startup form and/or executable file To start and stop an application in the IDE, use the Debug menu choice Code Editor window: used to display, write, and edit procedures

48 48 Programming with Microsoft Visual Basic 2005, Third Edition Completing the Copyright Screen Lesson C Objectives 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

49 49 Programming with Microsoft Visual Basic 2005, Third Edition Completing the Copyright Screen Lesson C Objectives (continued) Prevent the user from sizing a form Print the project’s code

50 50 Programming with Microsoft Visual Basic 2005, Third Edition Using the Timer Tool Splash screens typically close automatically –Timer control removes the 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

51 51 Programming with Microsoft Visual Basic 2005, Third Edition Using the Timer Tool (continued) Enabled property: allows timer to run if set to True Tick event –Occurs each time an interval has elapsed –Condition: the timer must be running (enabled) Add code into the Tick event procedure Component tray –Stores controls not visible in user interface at runtime

52 52 Programming with Microsoft Visual Basic 2005, Third Edition Using the Timer Tool (continued) Figure 1-40: Code entered in the xExitTimer’s Click event procedure

53 53 Programming with Microsoft Visual Basic 2005, Third Edition Setting the FormBorderStyle Property FormBorderStyle property –Determines the border style of a form Some settings and their descriptions –Fixed3D: fixed, three-dimensional –FixedDialog: fixed, thick dialog style –FixedSingle: fixed, thin line –None: no border

54 54 Programming with Microsoft Visual Basic 2005, Third Edition The MinimizeBox, MaximizeBox, and ControlBox Properties MinimizeBox property: determines whether the Minimize button appears on a form’s title bar MaximizeBox property: determines whether the Maximize button appears on a form’s title bar ControlBox property: determines whether title bar elements (icons/buttons) appear on a form Splash screens typically do not contain a title bar To remove title bar, delete content of form’s Text property

55 55 Programming with Microsoft Visual Basic 2005, Third Edition The MinimizeBox, MaximizeBox, and ControlBox Properties (continued) Figure 1-42: Completed copyright screen

56 56 Programming with Microsoft Visual Basic 2005, Third Edition Printing Your Code Print copy of code entered in the Code Editor window –Helps you understand and maintain the application Requirement for printing the code –Code editor window must be active, or current, window Print options –Hide collapsed regions –Include line numbers

57 57 Programming with Microsoft Visual Basic 2005, Third Edition Summary – Lesson C Timer control: processes code at specified intervals Use the form’s MinimizeBox and MaximizeBox properties to enable or disable the Minimize and Maximize buttons on the form Form’s ControlBox property: determines whether icon and control buttons will appear in the title bar Form’s BorderStyle property: determines if the form will be sizable at runtime Print Visual Basic code with Code Editor open


Download ppt "Chapter 1: An Introduction to Visual Basic 2005 Programming with Microsoft Visual Basic 2005, Third Edition."

Similar presentations


Ads by Google