Chapter 2 - VB 2008 by Schneider1 Chapter 2 –Visual Basic, Controls, and Events 2.1 An Introduction to Visual Basic 2.2 Visual Basic Controls 2.3 Visual.

Slides:



Advertisements
Similar presentations
Chapter 2 –Visual Basic, Controls, and Events
Advertisements

CS0004: Introduction to Programming Visual Studio 2010 and Controls.
Chapter 1: An Introduction to Visual Basic 2012
© by Pearson Education, Inc. All Rights Reserved.
Visual Basic 2010 How to Program. © by Pearson Education, Inc. All Rights Reserved.2.
Chapter 2 –Visual Basic, Controls, and Events
 2006 Pearson Education, Inc. All rights reserved Introduction to the Visual C# 2005 Express Edition IDE.
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.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
1 Introduction to the Visual Studio.NET IDE Powerpoint slides modified from Deitel & Deitel.
Chapter 2 –Visual Basic, Controls, and Events
CS0004: Introduction to Programming Events. Review  Event Procedure  A set of instructions to be executed when a certain event happens.  Many event-driven.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter One An Introduction to Visual Basic 2010.
Microsoft Visual Basic 2012 CHAPTER TWO Program and Graphical User Interface Design.
Visual Basic 2008 Express Edition The IDE. Visual Basic 2008 Express The Start Page Recent Projects Open an existing project Create a New Project.
Hello World In C++ and Microsoft Visual C++. Directions to begin a project 1. Go to All Programs 2. Open Visual Studio C++ 3. Click on New Project 4.
IE 411/511: Visual Programming for Industrial Applications
© 2006 Lawrenceville Press Slide 1 Chapter 3 Visual Basic Interface.
Tutorial 1: An Introduction to Visual Basic.NET1 Tutorial 1 An Introduction to Visual Basic.NET.
R EVIEW OF C HAPTER 1 1. Trouble installing/accessing Visual Studio? 2.
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.
Chapter 3: Using GUI Objects and the Visual Studio IDE.
Chapter 3 - VB.NET by Schneider1 Chapter 3 – Fundamentals of Programming in VB.NET VB.NET Controls VB.NET Events Numbers Strings Input and Output.
Chapter 3 - VB 2005 by Schneider1 Chapter 3 – Fundamentals of Programming in Visual Basic 3.1 Visual Basic Controls 3.2 Visual Basic Events 3.3 Numbers.
Chapter 3 – Fundamentals of Programming in VB.NET VB.NET Controls VB.NET Events Numbers Strings Input and Output.
Introduction to Visual Basic.NET Chapter 2 Introduction to Controls, Events.
Copyright © 2001 by Wiley. All rights reserved. Chapter 2: Using Visual Basic to Create a First Project Getting Started with VB Development Environment.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Introduction to Visual Basic.NET Your First Visual Basic.NET Application.
Microsoft Visual Basic 2012 CHAPTER THREE Program Design and Coding.
Chapter 2 –Visual Basic, Controls, and Events
1 Chapter 3 – Fundamentals of Programming in Visual Basic 3.1 Visual Basic Controls 3.2 Visual Basic Events 3.3 Numbers 3.4 Strings 3.5 Input and Output.
Chapter 2 - VB 2008 by Schneider1 Chapter 2 –Visual Basic, Controls, and Events 2.1 An Introduction to Visual Basic 2.2 Visual Basic Controls 2.3 Visual.
Chapter 2 – Introduction to the Visual Studio .NET IDE
3.2 VB.NET Events An Event Procedure Properties and Event Procedures of the Form Tab Order of Controls Exercises.
CSC 230 (Blum)1 Visual Basic 2005 Hello World Fall 2005 T. Blum.
Chapter 3 - VB.NET by Schneider1 Chapter 3 – Fundamentals of Programming in VB.NET Part I VB.NET Controls VB.NET Events.
© 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.
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter One An Introduction to Visual Basic 2008.
Object-Oriented Application Development Using VB.NET 1 Chapter 2 The Visual Studio.NET Development Environment.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
Chapter 31 Fundamentals of Programming in Visual Basic (VB) Visual Basic Events Simple Statement.
CSC 230 (Blum)1 Visual Basic 2005 Hello World Fall 2005 T. Blum.
Chapter 31 Fundamentals of Programming in Visual Basic (VB) Visual Basic Events Simple Statement.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
Introduction to Computer CC111 Week 10 Visual Basic 3 1.
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.
Programming with Microsoft Visual Basic 2012 Chapter 1: An Introduction to Visual Basic 2012.
ALMAJMA'AH UNIVERSITY College of Science and Humanitarians Studies in Alghat Information Technology Section (211Tal course) 1.
Chapter 1: An Introduction to Visual Basic .NET
Chapter 3 – Fundamentals of Programming in Visual Basic
Chapter 1: An Introduction to Visual Basic 2015
Chapter 2 – Introduction to the Visual Studio .NET IDE
3.01 Apply Controls Associated With Visual Studio Form
3.01 Apply Controls Associated With Visual Studio Form
An Introduction to Computers and Visual Basic
Do Now: What are the three steps to writing a Visual Basic Program?
Chapter 3 Fundamentals of Programming in Visual Basic 3
Chapter 2 – Introduction to the Visual Studio .NET IDE
An Introduction to Computers and Visual Basic
Fundamentals of Programming in VB.Net
Introduction to Programming
Presentation transcript:

Chapter 2 - VB 2008 by Schneider1 Chapter 2 –Visual Basic, Controls, and Events 2.1 An Introduction to Visual Basic 2.2 Visual Basic Controls 2.3 Visual Basic Events

Chapter 2 - VB 2008 by Schneider2 2.1 An Introduction to Visual Basic 2008 Why Windows and Why Visual Basic How You Develop a Visual Basic Application The Different Versions of Visual Basic

Chapter 2 - VB 2008 by Schneider3 Visual Basic 2008 Language used to create Windows applications. Provides a Graphical User Interface or GUI. The sequence of instructions executed in the program is controlled by events.

Chapter 2 - VB 2008 by Schneider4 Sample Input Screen

Chapter 2 - VB 2008 by Schneider5 How to Develop a Visual Basic Application Design the Interface for the user. Determine which events the controls on the window should recognize. Write the event procedures for those events.

Chapter 2 - VB 2008 by Schneider6 Different Versions of Visual Basic Version 1.0 – 1991 Version 2.0 – 1992 Version 3.0 – 1993 Version 4.0 – 1995 Version 5.0 – 1997 Version 6.0 – 1998 Visual Basic.NET – 2002 (NOT BACKWARD COMPATIBLE WITH EARLIER VERSIONS) Visual Basic 2005 – November 2005 Visual Basic 2008 – November 2007

Chapter 2 - VB 2008 by Schneider7 2.2 Visual Basic Controls Invoking Visual Basic Text Box Control Button Control Label Control List Box Control Name Property Help / Fonts / Auto Hide Positioning and Aligning Controls

Chapter 2 - VB 2008 by Schneider8 Visual Basic Start Page

Chapter 2 - VB 2008 by Schneider9 Start a New Project

Chapter 2 - VB 2008 by Schneider10 New Project Dialog Box

Chapter 2 - VB 2008 by Schneider11 Initial Visual Basic Screen

Chapter 2 - VB 2008 by Schneider12 Toolbox

Chapter 2 - VB 2008 by Schneider13 3 Ways to Place a Control from the Toolbox onto the Form Window Double-click Drag and Drop Click, Point, and Drag

Chapter 2 - VB 2008 by Schneider14 Four Controls at Design Time Text box To select a control, click on it. Sizing handles will appear when a control is selected.

Chapter 2 - VB 2008 by Schneider15 Text Box Control Used for input and output When used for output, ReadOnly property is set to True Sizing handles Tasks button

Chapter 2 - VB 2008 by Schneider16 Properties Window Categorized view Alphabetical view Press F4 to display the Properties window for the selected control.

Chapter 2 - VB 2008 by Schneider17 Properties Window PropertiesSettings Selected control

Chapter 2 - VB 2008 by Schneider18 Some Often Used Properties Text Autosize Font.Name Font.Size ForeColor BackColor ReadOnly

Chapter 2 - VB 2008 by Schneider19 Setting Properties Click on property name in left column. Enter its setting into right column by typing or selecting from options displayed via a button or ellipses.

Chapter 2 - VB 2008 by Schneider20 Setting the ForeColor Property 1.Click on ForeColor. 2.Click on button at right of settings box. 3.Click on Custom tab to obtain display shown. 4.Click on a color.

Chapter 2 - VB 2008 by Schneider21 Font Property 1.Click on Font in left column. 2.Click on ellipsis at right of settings box to obtain display shown, 3.Make selections.

Chapter 2 - VB 2008 by Schneider22 Button Control The caption on the button should indicate the effect of clicking on the button. Text property determines caption.

Chapter 2 - VB 2008 by Schneider23 Add an "access key"

Chapter 2 - VB 2008 by Schneider24 Label Control Used to identify the contents of a text box. Text property specifies caption. By default, label automatically resizes to accommodate caption on one line. When the AutoSize property is set to False, label can be resized manually. Used primarily to obtain a multi-rowed label.

Chapter 2 - VB 2008 by Schneider25 List Box Control Initially used to display several pieces of output. In Chapter 9 used to select from a list.

Chapter 2 - VB 2008 by Schneider26 The Name Property Used by the programmer to refer to a control in code Setting for Name property near top of Properties window. Name must begin with a letter, be less than 215 characters long, and may include numbers and letters. Use appropriate 3- or 4-character naming prefix

Chapter 2 - VB 2008 by Schneider27 Control Name Prefixes ControlPrefixExample buttonbtnbtnCompute labellbllblAddress text boxtxttxtAddress list boxlstlstOutput

Chapter 2 - VB 2008 by Schneider28 Renaming the Form Initial name is Form1 The Solution Explorer window lists a file named Form1.vb. To rename the form, change the name of this file to newName.vb newName should begin with prefix frm.

Chapter 2 - VB 2008 by Schneider29 Fonts Proportional width fonts take up less space for "I" than for "W" – like Microsoft Sans Serif Fixed-width fonts take up the same amount of space for each character – like Courier New Fixed-width fonts are used for tables.

Chapter 2 - VB 2008 by Schneider30 Auto Hide Hides Toolbox when not in use Vertical push pin icon indicates auto hide is disabled. Click the push pin to make it horizontal and enable auto hide. Push pin

Chapter 2 - VB 2008 by Schneider31 Positioning Controls Proximity line

Chapter 2 - VB 2008 by Schneider32 Aligning Controls Snap line

Chapter 2 - VB 2008 by Schneider33 Aligning Controls Snap line

Chapter 2 - VB 2008 by Schneider34 Tab Order Tab index The tab indices determine the order in which controls receive the focus during tabbing.

Chapter 2 - VB 2008 by Schneider Visual Basic Events An Event Procedure Walkthrough Properties and Event Procedures of the Form The Header of an Event Procedure

Chapter 2 - VB 2008 by Schneider36 Event An event is an action, such as the user clicking on a button Usually, nothing happens in a Visual Basic program until the user does something and generates an event. What happens is determined by statements.

Chapter 2 - VB 2008 by Schneider37 Sample Statements txtBox.ForeColor = Color.Red txtBox.Visible = True txtBox.Text = "Hello World" General Form: controlName.property = setting

Chapter 2 - VB 2008 by Schneider38 Sample Form txtFirst txtSecond btnRed

Chapter 2 - VB 2008 by Schneider39 Focus When you click on a text box, a cursor appears in the text box, and you can type into the text box. Such a text box is said to have the focus. If you click on another text box, the first text box loses the focus and the second text box receives the focus.

Chapter 2 - VB 2008 by Schneider40 Examples of Events btnShow.Click txtBox.TextChanged txtBox.Leave General Form: controlName.event

Chapter 2 - VB 2008 by Schneider41 The three steps in creating a Visual Basic program: 1.Create the interface; that is, generate, position, and size the objects. 2.Set properties; that is, configure the appearance of the objects. 3.Write the code that executes when events occur.

Chapter 2 - VB 2008 by Schneider42 Code Editor Method Name box Class Name box Code Editor tab Form Designer tab

Chapter 2 - VB 2008 by Schneider43 Structure of an Event Procedure Private Sub objectName_event(...) Handles objectName.event statements End Sub (...) is filled automatically with (ByVal sender As System.Object, ByVal e As System.EventArgs) Header

Chapter 2 - VB 2008 by Schneider44 Create an Outline for an Event Procedure; i.e. header and End Sub Double-click on a control or Use the Class Name and Method Name boxes. (We nearly always use the first method.)

Chapter 2 - VB 2008 by Schneider45 Sample Form txtFirst txtSecond btnRed Double Click on txtFirst

Chapter 2 - VB 2008 by Schneider46 Code for Walkthrough Public Class frmDemo Private Sub txtFirst_TextChanged(...) Handles txtFirst.TextChanged End Sub End Class

Chapter 2 - VB 2008 by Schneider47 Code for Walkthrough Public Class frmDemo Private Sub txtFirst_TextChanged(...) Handles txtFirst.TextChanged txtFirst.ForeColor = Color.Blue End Sub End Class

Chapter 2 - VB 2008 by Schneider48 IntelliSense Automatically pops up to give the programmer help. txtFirst.

Chapter 2 - VB 2008 by Schneider49 Code Editor Click tab to return to Form Designer

Chapter 2 - VB 2008 by Schneider50 Sample Form txtFirst txtSecond btnRed Double-click on btnRed

Chapter 2 - VB 2008 by Schneider51 Code for Walkthrough Public Class frmDemo Private Sub txtFirst_TextChanged(...) Handles txtFirst.TextChanged txtFirst.ForeColor = Color.Blue End Sub Private Sub btnRed_Click(...) Handles btnRed.Click End Sub End Class

Chapter 2 - VB 2008 by Schneider52 Code for Walkthrough Public Class frmDemo Private Sub txtFirst_TextChanged(...) Handles txtFirst.TextChanged txtFirst.ForeColor = Color.Blue End Sub Private Sub btnRed_Click(...) Handles btnRed.Click txtFirst.ForeColor = Color.Red End Sub End Class

Chapter 2 - VB 2008 by Schneider53 Event Procedure txtFirst.Leave Select txtFirst from Class Name box drop-down list. Select Leave from Method Name box drop-down list.

Chapter 2 - VB 2008 by Schneider54 Code for Walkthrough Private Sub txtFirst_Leave(...) Handles txtFirst.Leave End Sub Private Sub txtFirst_TextChanged(...) Handles txtFirst.TextChanged txtFirst.ForeColor = Color.Blue End Sub Private Sub btnRed_Click(...) Handles btnRed.Click txtFirst.ForeColor = Color.Red End Sub

Chapter 2 - VB 2008 by Schneider55 Code for Walkthrough Private Sub txtFirst_Leave(...) Handles txtFirst.Leave txtFirst.ForeColor = Color.Black End Sub Private Sub txtFirst_TextChanged(...) Handles txtFirst.TextChanged txtFirst.ForeColor = Color.Blue End Sub Private Sub btnRed_Click(...) Handles btnRed.Click txtFirst.ForeColor = Color.Red End Sub

Chapter 2 - VB 2008 by Schneider56 Header of Event Procedure Private Sub btnRed_Click(…) Handles btnRed.Click Identifies event Name, can be changed. Private Sub Button_Press(…) Handles btnRed.Click

Chapter 2 - VB 2008 by Schneider57 Handling Multiple Events Private Sub Happening(...) Handles btnRed.Click,txtSecond.Leave txtFirst.ForeColor = Color.Red End Sub Event procedure can be invoked by two events.

Chapter 2 - VB 2008 by Schneider58 Altering Properties of the Form The following won't work: frmDemo.Text = "Demonstration" The form is referred to by the keyword Me. Me.Text = "Demonstration"

Chapter 2 - VB 2008 by Schneider59 Text File Holds data to be processed by programs. Can be created, viewed, and managed by the Visual Basic IDE. Create : Use “Add New Item” input dialog box. View: Click on filename in Solution Explorer. Manage: Use Solution Explorer like Windows Explorer.

Chapter 2 - VB 2008 by Schneider60 Sample Text File Mike Jones John Smith PAYROLL.TXT

Chapter 2 - VB 2008 by Schneider61 Sample Text File Mike Jones John Smith name hourly wage hours worked PAYROLL.TXT

Chapter 2 - VB 2008 by Schneider62 Our Text File Convention PAYROLL.TXT uses one item of data per line. That will be our convention in this book.

Chapter 2 - VB 2008 by Schneider63 Use Property Window to View all Possible Events for a Control Events button

Chapter 2 - VB 2008 by Schneider64 Open and Run an Existing Program Click on Open Project in the File menu. Navigate to the program’s folder. Click on the program’s folder. Double-click on the file with extension.sln. In the Solution Explorer double-click on the file with extension.vb. (The Form Designer will appear.) Press F5 to run the program.