T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 4 Designing the Inventory Application Introducing TextBox es and Button s.

Slides:



Advertisements
Similar presentations
Microsoft Visual Basic: Reloaded Chapter Seven More on the Repetition Structure.
Advertisements

Chapter 5 Multitable Forms
© by Pearson Education, Inc. All Rights Reserved.
Visual Basic 2010 How to Program. © by Pearson Education, Inc. All Rights Reserved.2.
© by Pearson Education, Inc. All Rights Reserved. continued …
Visual Basic 2010 How to Program Reference: Instructor: Maysoon Bin Duwais slides Visual Basic 2010 how to program by Deitel © by Pearson Education,
 2006 Pearson Education, Inc. All rights reserved Introduction to the Visual C# 2005 Express Edition IDE.
Creating Custom Forms. 2 Design and create a custom form You can create a custom form by modifying an existing form or creating a new form. Either way,
Copyright 2007, Paradigm Publishing Inc. POWERPOINT 2007 CHAPTER 1 BACKNEXTEND 1-1 LINKS TO OBJECTIVES Create Presentation Open, Save, Run, Print, Close,Delete.
Chapter 31 Visual Basic Controls A Form is a windows-style screen displayed by Visual Basic programs. In a form, a programmer can create objects in a form.
Microsoft Visual Basic 2010: Reloaded Fourth Edition
1 Introduction to the Visual Studio.NET IDE Powerpoint slides modified from Deitel & Deitel.
Microsoft Visual Basic 2012 CHAPTER TWO Program and Graphical User Interface Design.
Microsoft Visual Basic 2005 CHAPTER 12 Cell Phone Applications and Web Services.
Tutorial 6 Using Form Tools and Creating Custom Forms
Create Database Tables
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Introducing Web Controls Outline 29.1 Analyzing the.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Interest Calculator Application Introducing the For...Next Repetition Statements.
IE 411/511: Visual Programming for Industrial Applications
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Typing Application Introducing Keyboard Events, Menus, Dialogs and the Dictionary.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 2 Welcome Application Introducing the Visual Basic 2008 Express Edition IDE.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide.
Chapter 3: Using GUI Objects and the Visual Studio IDE.
Visual Basic 2005 CHAPTER 2 Program and Graphical User Interface Design.
 2009 Pearson Education, Inc. All rights reserved Introduction to the Visual Basic Express 2008 IDE.
 2009 Pearson Education, Inc. All rights reserved Dive Into ® Visual C# 2008 Express.
Jozef Goetz,  2006 Pearson Education, Inc. All rights reserved.  2002 Prentice Hall. All rights reserved. expanded by J. Goetz, 2009.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 8 Dental Payment Application Introducing CheckBox es and Message Dialogs.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Key Applications Module Lesson 21 — Access Essentials
COMPREHENSIVE Access Tutorial 6 Using Form Tools and Creating Custom Forms.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 3 Welcome Application Introduction to Visual Programming.
Chapter Two Designing Applications Programming with Microsoft Visual Basic th Edition.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 5 Completing the Inventory Application Introducing Programming.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 17 – Flag Quiz Application Introducing One-Dimensional.
Using Microsoft Visual Studio 2005 Original by Suma Rao Revised by John G. McMahon ( 9/6/2008 )
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 3.1 Test-Driving the Welcome Application 3.2.
 2006 Pearson Education, Inc. All rights reserved Introduction to the Visual C# 2005 Express Edition IDE.
Chapter 2 – Introduction to the Visual Studio .NET IDE
CSC 230 (Blum)1 Visual Basic 2005 Hello World Fall 2005 T. Blum.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 2.1 Test-Driving the Welcome Application 2.2.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 5.1 Test-Driving the Inventory Application.
Microsoft Visual Basic 2010 CHAPTER TWO Program and Graphical User Interface Design.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to the Visual Studio.NET IDE Outline 2.1Introduction 2.2Visual Studio.NET Integrated.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Bookstore Web Application: Client Tier Introducing Web Controls.
Chapter 3 I Need a Tour Guide (Introduction to Visual Basic 2010) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 3 Building an Application in the Visual Basic.NET Environment.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Address Book Application Introducing Database Programming.
CSC 230 (Blum)1 Visual Basic 2005 Hello World Fall 2005 T. Blum.
Addison Wesley is an imprint of © 2011 Pearson Addison-Wesley. All rights reserved. Chapter 2 Creating Applications with Visual Basic.
XP New Perspectives on Microsoft Office Access 2003, Second Edition- Tutorial 6 1 Microsoft Office Access 2003 Tutorial 6 – Creating Custom Forms.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
 2009 Pearson Education, Inc. All rights reserved. 1 CS1120 Introduction to Windows Forms Applications Many slides modified by Prof. L. Lilien (even many.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
Microsoft Visual C# 2010 Fourth Edition Chapter 3 Using GUI Objects and the Visual Studio IDE.
 2007 Pearson Education, Inc. All rights reserved Introduction to the Visual Basic Express 2005 IDE.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
 You won’t write a single line of program code.  Instead, you’ll use visual programming techniques.  Visual Studio processes your actions (such as mouse.
Dive Into® Visual Basic 2010 Express
Chapter 1: An Introduction to Visual Basic .NET
Visual Studio 2010 Hello World CSC 230.
Chapter 2: The Visual Studio .NET Development Environment
Chapter 1: An Introduction to Visual Basic 2015
Chapter 2 – Introduction to the Visual Studio .NET IDE
Program and Graphical User Interface Design
How to design a Windows Forms application
Program and Graphical User Interface Design
Visual Studio 2010 Hello World CSC 230.
Chapter 2 – Introduction to the Visual Studio .NET IDE
Presentation transcript:

T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 4 Designing the Inventory Application Introducing TextBox es and Button s

 2009 Pearson Education, Inc. All rights reserved. 2 Outline 4.1 Test-Driving the Inventory Application 4.2 Constructing the Inventory Application 4.3 Adding Label s to the Inventory Application 4.4 Adding TextBox es and a Button to the Form

 2009 Pearson Education, Inc. All rights reserved. 3 In this tutorial you will learn: ■Set the text in the Form ’ s title bar. ■Visually program, using GUI design guidelines. ■Rename the Form. ■Add TextBox es and a Button to the Form. ■Use the BorderStyle property for Label s. Objectives

Application Requirements  2009 Pearson Education, Inc. All rights reserved Test-Driving the Inventory Application A college bookstore receives cartons of textbooks. In each shipment, all cartons contain the same number of textbooks. The inventory manager wants to use a computer to calculate the total number of textbooks arriving at the bookstore for each shipment. The inventory manager will enter the number of cartons received and the fixed number of textbooks in each carton for each shipment; then the application will calculate the total number of textbooks in the shipment.

 2009 Pearson Education, Inc. All rights reserved. 5 ■Navigate to the directory C:\Examples\ Tutorial04\CompletedApp- lication\Inventory and open the Inventory application. ■Select Debug > Start Debugging to run the application (Fig. 4.1). ■A TextBox is a control that the user can enter data into from the keyboard. ■A Button is a control that causes the application to perform an action when clicked. Test-Driving the Inventory Application Label Figure 4.1 | Inventory application Form with default data displayed by the application. Button Label TextBoxes Label

 2009 Pearson Education, Inc. All rights reserved. 6 Figure 4.2 | Inventory application with new quantities entered. Test-Driving the Inventory Application (Cont.) ■When controls do not display self-descriptive text, we use Label s to identify them. ■Enter the values shown in Figure 4.2.

 2009 Pearson Education, Inc. All rights reserved. 7 Figure 4.3 | Result of clicking the Calculate Total Button in the Inventory application. Test-Driving the Inventory Application (Cont.) ■Clicking the Calculate Total Button causes the application to multiply the two numbers you entered and to display the result (Fig. 4.3). Result of calculation

 2009 Pearson Education, Inc. All rights reserved. 8 ■To create a Windows application, select File > New Project.... ■From the list of templates (Fig. 4.4), select Windows Forms Application. Creating a New Application Figure 4.4 | New Project dialog for creating new applications. Templates: pane with Windows Forms Application selected Name: TextBox

 2009 Pearson Education, Inc. All rights reserved. 9 Figure 4.5 | Save Project dialog for saving the newly created application. Creating a New Application (Cont.) ■Select File > Save All (Fig. 4.5).

 2009 Pearson Education, Inc. All rights reserved. 10 ■Click the Browse... Button, and the Project Location dialog appears (Fig. 4.6). ■Navigate to C:\SimplyVB2008. Click Select Folder to select the directory and dismiss the dialog. Creating a New Application (Cont.) Figure 4.6 | Project Location dialog used to specify the directory in which the project files reside. Working directory

 2009 Pearson Education, Inc. All rights reserved. 11 Creating a New Application (Cont.) ■Change the Form ’s file name to a name more meaningful for your application. –To do so, click the Form ’s file name in the Solution Explorer (Fig. 4.7). –Then select File Name in the Properties window, and type Inventory.vb in the field to the right.

 2009 Pearson Education, Inc. All rights reserved. 12 Figure 4.7 | New Windows application in Visual Studio. Creating a New Application (Cont.) Form title bar (for Form1) Form Form title bar (Form1.vb) Properties window (for Form1)

 2009 Pearson Education, Inc. All rights reserved. 13 Creating a New Application (Cont.) ■Each Form object needs a unique and meaningful name for easy identification. ■Set the Form ’s name by using the Name property. –In the Properties window (Fig. 4.8), change the Form ’s name to InventoryForm. –Then press Enter to update the name. Name property Type new Form’s name here Figure 4.8 | Renaming a Form in the Properties windows.

 2009 Pearson Education, Inc. All rights reserved. 14 Good Programming Practice Change the Form name to a unique and meaningful name for easy identification.

 2009 Pearson Education, Inc. All rights reserved. 15 Good Programming Practice Use standard suffixes for names of objects (controls and Form s) so that you can easily tell them apart. Append the suffix Form to Form names. Capitalize the first letter of the Form name because Form is a class. Objects (such as controls) should begin with lowercase letters.

 2009 Pearson Education, Inc. All rights reserved. 16 Customizing the Form ■To change the Form ’s font to 9pt Segoe UI : –click the plus box to the left of the Font property (Fig. 4.9). –Change the font’s Name and Size properties as shown in the next slide. Click plus box to display Font properties

 2009 Pearson Education, Inc. All rights reserved. 17 Click down arrow to display drop-down list Name property Customizing the Form (Cont.) Figure 4.9 | Setting a Form ’s font to 9pt Segoe UI. Select Segoe UI from drop-down list Size property

 2009 Pearson Education, Inc. All rights reserved. 18 Change the Form ’s font to 9pt Segoe UI to be consistent with Microsoft’s recommended font for Windows Vista. GUI Design Tip

 2009 Pearson Education, Inc. All rights reserved. 19 ■The text in the Form ’s title bar is determined by the Form ’s Text property. ■Double click the field to the right of the Text property in the Properties window, and change it to Inventory. ■Double click the field to the right of the Size property in the Properties window, then enter 320, 112 and press Enter (Fig. 4.10). Customizing the Form (Cont.) Figure 4.10 | Resized Form displaying new title-bar text. Title-bar text set to Inventory

 2009 Pearson Education, Inc. All rights reserved. 20 Changing the Form ’s title allows users to identify the Form ’s purpose. GUI Design Tip

 2009 Pearson Education, Inc. All rights reserved. 21 Form titles should use book-title capitalization. GUI Design Tip

 2009 Pearson Education, Inc. All rights reserved Adding Labels to the Inventory Application ■There are four Label s in this application. ■You can easily recognize three of the Label s. The fourth Label, however, has a border and contains no text until the user clicks the Calculate Total Button (Fig. 4.11). ■As the control’s name indicates, Label s are often used to identify other controls on the Form. –Descriptive Label s help the user understand each control’s purpose. –Output Label s display program output.

 2009 Pearson Education, Inc. All rights reserved. 23 Figure 4.11 | Label s used in the Inventory application. Descriptive Labels Descriptive Label Output Label (recessed appearance) 4.3 Adding Label s to the Inventory Application (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 24 Figure 4.12 | Adding a Label to the Form. Adding Label s to the Form ■Click the All Windows Forms group in the Toolbox and place a Label on the Form (Fig. 4.12). Location value 0, 0 Label control ■Set the Label ’s Location property to 9, 15. ■You can also change a control’s position by selecting it and using the arrow keys to move it.

 2009 Pearson Education, Inc. All rights reserved. 25 Leave space between the edges of the Form and its controls. GUI Design Tip

 2009 Pearson Education, Inc. All rights reserved. 26 ■The Label ’s Location property specifies the position of the upper-left corner of the control on the Form. ■A control’s Location property is set according to its distance from that point on the Form. ■In this case, the value 9, 15 indicates that the Label is placed 9 pixels to the right and 15 pixels down from the top-left corner. ■Enter Cartons per shipment: in the Text property. Set the Name property to cartonsLabel. Adding Label s to the Form (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 27 The Location property can be used to specify a control’s precise position on the Form. GUI Design Tip

 2009 Pearson Education, Inc. All rights reserved. 28 Good Programming Practice Append the Label suffix to all Label control names.

 2009 Pearson Education, Inc. All rights reserved. 29 ■When entering values for a Label ’s Text property, you should use sentence-style capitalization. ■Select the TextAlign property and click its down arrow (Fig. 4.13). ■Select the middle-left rectangle, which indicates the value MiddleLeft. Adding Label s to the Form (Cont.) Figure 4.13 | Changing the TextAlign property of a Label. TextAlign property Value of TextAlign property (MiddleLeft) MiddleLeft TextAlign property value Down arrow Window displayed when down arrow is clicked

 2009 Pearson Education, Inc. All rights reserved. 30 GUI Design Tip The TextAlign property of a descriptive Label should be set to MiddleLeft. This ensures that text within groups of Label s align.

 2009 Pearson Education, Inc. All rights reserved. 31 Figure 4.14 | GUI after the Label has been customized. Adding Label s to the Form (Cont.) Location 9, 15 ■Figure 4.14 displays the Label after you set its properties.

 2009 Pearson Education, Inc. All rights reserved. 32 ■Add a second Label named itemsLabel. –Set its Location property to 9, 46. –Set the Label ’ s Text property to Items per carton: –Set the Label ’ s TextAlign property to MiddleLeft. ■Add a third Label named totalLabel. –Set its Location property to 190, 15. –Set the Label ’ s Text property to Total: –Then set the Label ’ s TextAlign property to MiddleLeft. Placing Additional Label s on the Form

 2009 Pearson Education, Inc. All rights reserved. 33 GUI Design Tip Align the left or right sides of a group of descriptive Label s if the Label s are arranged vertically.

 2009 Pearson Education, Inc. All rights reserved. 34 ■Add a fourth Label named totalResultLabel. –Set its AutoSize property to False. –Set the Label ’ s Size property to 50, 23 and the Location property to 243, 11. –Set the Label ’ s TextAlign property to MiddleCenter (Fig. 4.15). Placing Additional Label s on the Form (Cont.) MiddleCenter TextAlign property value Figure 4.15 | Setting the TextAlign property to MiddleCenter.

 2009 Pearson Education, Inc. All rights reserved. 35 GUI Design Tip If several output Label s are arranged vertically to display numbers used in a mathematical calculation (such as in an invoice), use the MiddleRight value for the Text­Align property.

 2009 Pearson Education, Inc. All rights reserved. 36 ■Make the totalResultLabel appear different from the other Label s by changing the BorderStyle property. Assign the value Fixed3D (Fig. 4.16) to make the Label seem three-dimensional (Fig. 4.17). Fixed3D BorderStyle property value highlighted Figure 4.16 | Changing a Label ’s BorderStyle property to Fixed3D. Placing Additional Label s on the Form (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 37 GUI Design Tip Output Label s should be distinguishable from descriptive Label s. This can be done by setting the BorderStyle property of an output Label to Fixed3D.

 2009 Pearson Education, Inc. All rights reserved. 38 ■Clear the text of the Label, because you will not be adding meaningful text to totalResultLabel until later. ■Figure 4.17 displays the GUI with all Label s added. Label with Fixed3D BorderStyle property Placing Additional Label s on the Form (Cont.) Figure 4.17 | GUI with all Label s added.

 2009 Pearson Education, Inc. All rights reserved. 39 Good Programming Practice Clear the an output Label ’s value initially or provide a default value. When the application performs the calculation for that value, the Label ’s Text property should be updated to the new value. You’ll learn how to do this in the next tutorial.

 2009 Pearson Education, Inc. All rights reserved. 40 ■Double click the TextBox control in the Toolbox to add a TextBox to the Form. ■Select its Name property and enter cartonsTextBox (Fig. 4.18). Set the Width property to 40 and Location property to 136, 12. Set the TextBox ’s Text property to 0. Adding TextBox es to the Form

 2009 Pearson Education, Inc. All rights reserved. 41 Name property set to cartonsTextBox Adding TextBox es to the Form (Cont.) Figure 4.18 | Properties window for the cartonsTextBox TextBox. Location property set to 136, 12 Width property set to 40

 2009 Pearson Education, Inc. All rights reserved. 42 GUI Design Tip Use TextBox es to input data from the keyboard.

 2009 Pearson Education, Inc. All rights reserved. 43 ■Change cartonsTextBox ’s Text­Align property to Right. ■ TextBox es have fewer TextAlign options, which are displayed simply as a list. Select Right from this list (Fig. 4.19). ■Add a TextBox named itemsTextBox. Set the Width property to 40 and the Location property to 136, 43. Set the Text property to 0 and the TextAlign property to Right. Adding TextBox es to the Form (Cont.) Figure 4.19 | Selecting value Right of the TextAlign property of a TextBox control.

 2009 Pearson Education, Inc. All rights reserved. 44 GUI Design Tip Each TextBox should have a descriptive Label indicating the input expected from the user.

 2009 Pearson Education, Inc. All rights reserved. 45 GUI Design Tip Place each descriptive Label either above or to the left of the control (for instance, a TextBox ) that it identifies.

 2009 Pearson Education, Inc. All rights reserved. 46 ■Many of the second TextBox ’s properties match those of the first TextBox, so it may be easier to copy the original control. –To do this, select the control you wish to copy and press Ctrl + C. –Then press Ctrl + V to paste it onto the Form. ■Figure 4.20 shows the resulting GUI. Figure 4.20 | GUI after TextBox es have been added and modified. Adding TextBox es to the Form (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 47 GUI Design Tip Make TextBox es wide enough for their expected inputs.

 2009 Pearson Education, Inc. All rights reserved. 48 GUI Design Tip A descriptive Label and the control it identifies should be aligned on the left if they are arranged vertically.

 2009 Pearson Education, Inc. All rights reserved. 49 ■Add a Button to the Form by double clicking the Button control, and enter calculateButton for its Name property. ■Set the Button ’s Size to 100, 24 and Location to 193, 42. Then drag the sizing handle on the right side of the Button until the Button is aligned with the right side of the Label above it. ■Enter Calculate Total in the Button ’s Text property. You should use book-title capitalization in a Button ’s Text property. Adding a Button to the Form

 2009 Pearson Education, Inc. All rights reserved. 50 Good Programming Practice Append the Button suffix to Button control names.

 2009 Pearson Education, Inc. All rights reserved. 51 ■Run the completed application (Fig. 4.21). Figure 4.21 | Running the application after completing its design. Adding a Button to the Form (Cont.) Close box