Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 1: An Introduction to Visual Basic 2015

Similar presentations


Presentation on theme: "Chapter 1: An Introduction to Visual Basic 2015"— Presentation transcript:

1 Chapter 1: An Introduction to Visual Basic 2015

2 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 Change the layering order of controls Center controls on the form Open the Project Designer window 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 Programming with Microsoft Visual Basic 2015

3 Wndows In lesson 1A you have learned about:
Windows Form Designer Solution Explorer Window Properties Window In this lesson you will learn about the Toolbox window (also known as toolbox) The toolbox contains the tools you will use to create your application’s user interface Each tool represents a class from which an object such as a button or textbox can be instantiated Instantiated objects called controls will appear on the form Programming with Microsoft Visual Basic 2015

4 The Toolbox Window Class Object Toolbox window (or toolbox) Controls
A pattern from which an object is created Object An 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 the toolbox Controls GUI objects that appear on a form Programming with Microsoft Visual Basic 2015

5 The Toolbox Window (cont.)
Figure 1-13 Toolbox window showing the purpose of the Label tool Programming with Microsoft Visual Basic 2015

6 The Label Tool (p29) Use the Label tool to add a label control to a form A label control displays text that cannot be edited at run time (it means that the user is not allowed to modify) Notice that Appears in the Object box in the properties window Label1 is the Label1 is the default name assigned to the label control System.Windows.Forms.Label indicates that the control is an instance of the Label class Programming with Microsoft Visual Basic 2015

7 The Label Tool (p29) Name property (p30) Text property (p31)
A unique name for a control Text property (p31) Specifies the value that appears in a label control Location property (p31) Specifies the location of a control on a form Includes an X value and a Y value How do you select a control on the form without clicking on it? Your answer is: ? Programming with Microsoft Visual Basic 2015

8 Figure 1-15 Label control added to the form
The Label Tool (cont.) Figure 1-15 Label control added to the form Programming with Microsoft Visual Basic 2015

9 The Label Tool (cont.) Setting the Text Property
Select the lblMsg control Click text in the Properties list Type Come visit our residents! Press Enter Verify that the AutoSize property is set to True Select the lblName control Type Crighton Zoo Programming with Microsoft Visual Basic 2015

10 The Label Tool (cont.) Setting the Location Property
Select the lblMsg control Click Location in the Properties list Expand the Location property by clicking the plus box Type 180, 115 Press Enter Select the lblName control Type 180, 70 Programming with Microsoft Visual Basic 2015

11 Changing a Property For Multiple Controls (p31)
A control inherits the font attribute of the form Sometimes You may want to use different font type, style, or size for a control text You can change the font, the size o other property of one control (or more than one control of the same class) In the Splash screen You can make the text in the two label controls more noticeable by increasing the size of the font used to display text (p31) Select the first control, hold down the Ctrl (Control) key as you select the other control (or controls) on the form Figure 1-16 Label controls selected on the form Programming with Microsoft Visual Basic 2015

12 Changing a Property For Multiple Controls (p31)
A control inherits the font attribute of the form Sometimes You may want to change the default values To simultaneously modify similar controls: Click one control and then press and hold the Ctrl key Click other similar control(s) in the form, or click and drag to group the controls Set the property value in the Properties list Figure 1-16 Label controls selected on the form Programming with Microsoft Visual Basic 2015

13 Changing a Property For Multiple Controls (cont.)
Using the Format Window’s Order Option (p32) The Format menu contains an Order option that allows you to control the layering of one or more controls on a form Using the Format Menu’s Order Option (p32) Change the form’s Backcolor property to dark green Add… 3… Figure 1-17 New label on top of previous labels Programming with Microsoft Visual Basic 2015

14 Changing a Property For Multiple Controls (cont.)
Using the Format Window’s Order Option (p32) To layer one control over another layer Create a label control and size it to cover other labels Figure 1-17 New label on top of previous labels Programming with Microsoft Visual Basic 2015

15 Changing a Property For Multiple Controls (cont.)
Using the Format Window’s Order Option (p33) To reverse the layers Click the label control on the form Click Format on the menu bar Point to Order and then click Send to Back Figure 1-17 New label on top of previous labels Programming with Microsoft Visual Basic 2015

16 The PictureBox Tool (p33)
You can include an image on a form using a picture box control which you instantiate using the picture box control Programming with Microsoft Visual Basic 2015

17 The PictureBox Tool (p33)
Creates a 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 A project’s resource file contains imported images Figure 1-19 Open task list for a picture box Figure 1-20 Completed Select Resource dialog box Programming with Microsoft Visual Basic 2015

18 The PictureBox Tool (cont.)
Figure 1-21 Picture boxes added to the form Programming with Microsoft Visual Basic 2015

19 The PictureBox Tool (cont.)
Using the Format Menu to Align and Size (p35) The Format menu provides a Center in Form options for centering one or more controls either vertically or horizontally on the form The Format menu also provides an align option for aligning two or more controls by their left, right, top, or bottom borders The menu Make Same Size option allows to make to or more two or more controls the same width and/or height Before you can use the Format menu to change the alignment or size of two or more controls, you must first select the controls Programming with Microsoft Visual Basic 2015

20 The PictureBox Tool (cont.)
Select the reference control first . The reference control is the one whose size and/or location you want to match The reference control will have white sizing handles, Whereas the other selected controls will have black sizing handles Programming with Microsoft Visual Basic 2015

21 The Button Tool (p36) Every application should give the user a way to exit a program Most Windows applications accomplish the task by using either an exit option on the File menu or an exit button In this lesson the splash screen will provide a button for ending the application In Windows applications a button control is commonly used to perform an immediate action when clicked The OK and Cancel button are examples of button controls found in many Windows applications. Programming with Microsoft Visual Basic 2015

22 The Button Tool Used to create a button control
Used to perform an action when clicked Examples: OK and Cancel buttons Common means of exiting a Windows application: Exit option on the FILE menu Exit button Programming with Microsoft Visual Basic 2015

23 The Button Tool Steps to add a Button control to the form (p36)
Use the button tool in the toolbox The three-character ID used when naming button control is btn Programming with Microsoft Visual Basic 2015

24 Starting and Ending an Application
Startup form Displays when an application is first started The Project Designer window specifies the startup form or the executable code to be run Right-click My Project in the Solution Explorer window and then click Open Or, click PROJECT on the menu bar and then click <project name> Properties Application tab Specify startup form Programming with Microsoft Visual Basic 2015

25 Programming with Microsoft Visual Basic 2015

26 Starting and Ending an Application (cont.)
Executable file A file that can be run outside of the IDE Its filename ends with .exe It is automatically created when a Visual Basic application is started Two ways to start an application in the IDE: Click DEBUG on the menu bar and then click Start Debugging Press the F5 key Figure 1-22 Application pane in the Project Designer window Programming with Microsoft Visual Basic 2015

27 The Code Editor Window (p 39)
After creating your application interface, you can begin entering the Visual Basic instructions (code) that tells the controls how to respond to the user’s actions Those actions such as clicking, double-clicking, and scrolling are called events You tell an object how to respond to an event by writing an event procedure which is a set of Visual Basic instructions that are processed only when the event occurs. You enter the procedure’s code in the Code Editor window. In this lesson you will write a Click event procedure for the Exit button which should end the application when it is clicked Programming with Microsoft Visual Basic 2015

28 The Code Editor Window Events Event procedure Code Editor window
User actions such as double-clicking Event procedure A set of program instructions that are processed when an event occurs Code Editor window Provides templates for creating event procedures To open it, right-click the form and then click View Code Programming with Microsoft Visual Basic 2015

29 The Code Editor Window (cont.)
Figure 1-24 Code Editor window opened in the IDE Programming with Microsoft Visual Basic 2015

30 The Code Editor Window (p39)
Figure 1-26 was obtained using Visual Studio lets use this figure to illustrate the paragraph at the bottom of page 39 Project list box Object list box Method list box This Code Editor window contains three (the Visual Studio 2013 provides only two) dropdown list boxes Programming with Microsoft Visual Basic 2015

31 The Code Editor Window (cont.)
Dropdown list boxes named: Project Object Method T he project box contains the name of the current project: Splash Project The object box lists the names of the objects included in the user interface The method box lists the events to which the selected object is capable of responding Programming with Microsoft Visual Basic 2015

32 The Code Editor Window (cont.)
In object-oriented programming (OOP), an event is considered a behavior of an object because it represents an action to which the object can respond In (OOP), the Code Editor window “exposes” an object’s behavior to the programmer You use the Object and Method list boxes to select the object and event, respectively, that you want to code In this case you will select btnExit in the Object list box, and you will select Click in the Method list box This is because you want the application to end when the Exit button is clicked Programming with Microsoft Visual Basic 2015

33 The Code Editor Window (p 40 cont.)
To select the btnExit control’s Click event (p40): 1. Click the object list arrow and then click btnExit in the list Click the Method list arrow and then click and then click Click in the list…. A code template for the btnExit control’s click event procedure appears in the Code Editor window (see Figure 1-26) Figure 1-26 btnExit control’s Click event procedure The code editor provides the code template to help you follow the rules of the Visual Basic language Programming with Microsoft Visual Basic 2015

34 The Code Editor Window (p 40 cont.)
Syntax: The rules of a programming language are called its syntax OOP: Object-oriented programming; events are clickable Procedure header: The first line in the code template for an event procedure Procedure footer: The last line in the code template for an event procedure Keyword: A word that has a special meaning in a programming language Keywords appear in different color than the rest of the code The Private keyword in Figure 1-26 indicates that the button’s Click event procedure can be used only within the current Code Editor window Programming with Microsoft Visual Basic 2015

35 The Code Editor Window (p 40 cont.)
Keyword: A word that has a special meaning in a programming language Keywords appear in different color than the rest of the code The Private keyword in Figure 1-26 indicates that the button’s Click event procedure can be used only within the current Code Editor window The Sub keyword is an abbreviation of the term sub procedure, which is a block of code that performs a specific task Programming with Microsoft Visual Basic 2015

36 The Code Editor Window (cont.)
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 event name Example: btnExit.Click Programming with Microsoft Visual Basic 2015

37 The Code Editor Window (p 40 cont.)
With Visual Studio 2013 you have this Code Editor window Programming with Microsoft Visual Basic 2015

38 The Code Editor Window (cont.)
OOP Object-oriented programming; events are clickable Syntax The rules of a programming language Procedure header The first line in the code template for an event procedure Prcoedure footer The last line in the code template for an event procedure Programming with Microsoft Visual Basic 2015

39 The Code Editor Window (cont.)
The Me.Close() Instruction Method A predefined procedure Can be called (or invoked) when needed Me.Close() method Causes the current form to close If it is the only form in an application, the application terminates IntelliSense feature Provides appropriate selections as pop-up lists Type the first few letters of your choice Then use the arrow keys to select an item in the list Programming with Microsoft Visual Basic 2015

40 The Code Editor Window (cont.)
Figure 1-27 List displayed by the IntelliSense feature Programming with Microsoft Visual Basic 2015

41 Lesson B Summary To add a control to a form, use a tool from the toolbox Use the label control for text that users cannot edit You can set the properties of multiple controls simultaneously To start and stop an application in the IDE, use DEBUG on the menu bar Use the Code Editor window to display an object’s event procedures The Me.Close() method closes the current form at run time Programming with Microsoft Visual Basic 2015


Download ppt "Chapter 1: An Introduction to Visual Basic 2015"

Similar presentations


Ads by Google