Chapter 2 Visual Basic, Controls, and Events. 2.1 An Introduction to Visual Basic 2.2 Visual Basic Controls 2.3 Visual Basic Events

Similar documents
REVIEW OF CHAPTER 1 1

Introducing Visual Basic

Chapter 3. Fundamentals of Programming in Visual Basic

Introducing Visual Basic

Program and Graphical User Interface Design

Dive Into Visual C# 2008 Express

Computer Science 110. NOTES: module 8

HOW TO DEVELOP A VB APPLICATION

STUDENT SOLUTIONS MANUAL

Skill Area 336 Explain Essential Programming Concept. Programming Language 2 (PL2)

Tutorial 03 understanding controls : buttons, text boxes

2 USING VB.NET TO CREATE A FIRST SOLUTION

LESSON A. The Splash Screen Application

COPYRIGHTED MATERIAL. Visual Basic: The Language. Part 1

Introduction to the Visual Studio.NET Integrated Development Environment IDE. CSC 211 Intermediate Programming

Working with Images 1 / 12

Review. October 20, 2006

GUI Design and Event- Driven Programming

Using Visual Basic Studio 2008

Departme and. Computer. CS Intro to. Science with. Objectives: The main. for a problem. of Programming. Syntax Set of rules Similar to.

LESSON B. The Toolbox Window

Text box. Command button. 1. Click the tool for the control you choose to draw in this case, the text box.

Chapter 2. Creating Applications with Visual Basic Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of

Dive Into Visual C# 2010 Express

Display Systems International Software Demo Instructions

Welcome Application. Introducing the Visual Studio.NET IDE. Objectives. Outline

Visual Basic 2008 The programming part

Disclaimer. Trademarks. Liability

Visual Basic.NET. 1. Which language is not a true object-oriented programming language?

IT3101 -Rapid Application Development Second Year- First Semester. Practical 01. Visual Basic.NET Environment.

CST242 Windows Forms with C# Page 1

Customization Manager

Full file at

Compare and Merge Track Changes

FOR 240 Homework Assignment 4 Using DBGridView and Other VB Controls to Manipulate Database Introduction to Computing in Natural Resources

Using Windows 7 Explorer By Len Nasman, Bristol Village Computer Club

Tutorial 2 - Welcome Application Introducing, the Visual Studio.NET IDE

Join Queries in Cognos Analytics Reporting

Getting Started with Visual Basic.NET

Editing the Home Page

Programming in C# Project 1:

POS Designer Utility

Visual C# Program: Simple Game 3

The first program we write will display a picture on a Windows screen, with buttons to make the picture appear and disappear.

Getting Started with Access

CIS 3260 Intro. to Programming with C#

Starting Excel application

Introduction to Microsoft Word 2008

USING MICROSOFT ACCESS 2013 Guided Project 7-1

Nauticom NetEditor: A How-to Guide

MockupScreens - User Guide

Introduction. Getting Started with Visual Basic Steps:-

Exploring Microsoft Office Word 2007

CHANNEL9 S WINDOWS PHONE 8.1 DEVELOPMENT FOR ABSOLUTE BEGINNERS

Introductionto the Visual Basic Express 2008 IDE

Wyo VB Lecture Notes - Objects, Methods, & Properties

Chapter 2 Visual Basic, Controls, and Events

Lab 4: Adding a Windows User-Interface

Corel Ventura 8 Introduction

Full file at Programming in Visual Basic 2010

The Newsletter will contain a Title for the newsletter, a regular border, columns, Page numbers, Header and Footer and two images.

The Filter Property Selecting a File The Save Menu The SaveFileDialog Control The Edit Menu The Copy Menu...

INTRODUCTION TO VISUAL BASIC 2010

Excel 2007 New Features Table of Contents

2. In the Start and End Dates section, use the Calendar icon to change the Displayed Start Date to 1/1/2015 and the Displayed End Date to 5/31/2015.

Lecture 1 Introduction Phil Smith

Power BI Desktop Lab

SPARK. User Manual Ver ITLAQ Technologies

Microsoft Office Outlook 2007: Intermediate Course 01 Customizing Outlook

Dataflow Editor User Guide

SmartArt Office 2007

Form into function. Getting prepared. Tutorial. Paul Jasper

Access Review. 4. Save the table by clicking the Save icon in the Quick Access Toolbar or by pulling

Using Adobe Contribute 4 A guide for new website authors

Tutor Handbook for WebCT

Getting started 7. Setting properties 23

Getting started 7. Setting properties 23

Chapter 2 Exploration of a Visual Basic.Net Application

MICROSOFT WORD 2010 BASICS

In the first class, you'll learn how to create a simple single-view app, following a 3-step process:

Tabs, Tables & Columns

Outlook basics. Identify user interface elements that you can use to accomplish basic tasks.

Customize the Navigation Pane

Add Tags to a Sent Message [New in v0.6] Misc 2

Multimedia web page Board

Adobe InDesign CS6 Tutorial

Status Bar: Right click on the Status Bar to add or remove features.

Visual Basic. murach s. (Chapter 2) TRAINING & REFERENCE. Mike Murach & Associates, Inc.

TIDY LABELS. User Guide

Tutorial 3 - Welcome Application

HOUR 4 Understanding Events

Let s Make a Front Panel using FrontCAD

How to set up a local root folder and site structure

FLIR Tools+ and Report Studio

Sema Foundation ICT Department. Lesson - 18

More Skills 11 Format and Position Report Controls

Database Design Lab: MS Access Queries

LaGuardia Community College Thomson Ave, Long Island City, New York Created by ISMD s Dept. Training Team.

ADJUST TABLE CELLS-ADJUST COLUMN AND ROW WIDTHS

Libraries. Multi-Touch. Aero Peek. Sema Foundation 10 Classes 2 nd Exam Review ICT Department 5/22/ Lesson - 15

Transcription:

Chapter 2 Visual Basic, Controls, and Events 2.1 An Introduction to Visual Basic 2.2 Visual Basic Controls 2.3 Visual Basic Events 1

2.1 An Introduction to Visual Basic 2010 Why Windows and Why Visual Basic How You Develop a Visual Basic Application The Different Versions of Visual Basic 2

Visual Basic 2010 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. 3

Sample Input Screen 4

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. 5

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 Visual Basic 2010 April 2010 6

2.2 Visual Basic Controls Starting a New Visual Basic Program Text Box Control Button Control Label Control List Box Control Name Property Fonts / Auto Hide Positioning and Aligning Controls 7

Visual Basic Start Page 8

Start a New Project 9

New Project Dialog Box select click on OK button 10

Initial Visual Basic Screen 11

Toolbox 12

4 Ways to Place a Control from the Toolbox onto the Form Designer Double-click Drag and Drop Click, Point, and Click Click, Point, and Drag 13

Four Controls at Design Time text box To select a control, click on it. Sizing handles will appear when a control is selected. 14

Text Box Control Used for input and output When used for output, ReadOnly property is set to True Tasks button sizing handles 15

Properties Window Press F4 to display the Properties window for the selected control. categorized view alphabetical view 16

Properties Window (continued) selected control properties settings Description pane 17

Some Often Used Properties Text Autosize Font.Name Font.Size ForeColor BackColor ReadOnly 18

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. 19

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. 20

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. 21

Button Control The caption on the button should indicate the effect of clicking on the button. Text property 22

Add an Access Key 23

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. AutoSize is used primarily to obtain a multi-rowed label. 24

List Box Control Initially used to display several pieces of output. In Chapter 4 used to select from a list. 25

The Name Property Used by the programmer to refer to a control in code Setting for Name property near top of Properties window Use appropriate 3-character naming prefix Use descriptive names 26

Control Name Prefixes Control Prefix Example button btn btncompute label lbl lbladdress text box txt txtaddress list box lst lstoutput 27

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. 28

Fonts Proportional width fonts, such as Microsoft Sans Serif, use less space for "I" than for "W" Fixed-width fonts take up the same amount of space for each character like Courier New Fixed-width fonts are used for tables. 29

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 30

Positioning Controls proximity line 31

Aligning Bottoms of Controls snap line 32

Aligning Middles of Controls snap line 33

Tab Order The tab indices determine the order in which controls receive the focus during tabbing. The control whose TabIndex property is set to 0 has the focus when the program begins. 34

2.3 Visual Basic Events An Event Procedure Walkthrough Properties and Event Procedures of the Form The Header of an Event Procedure 35

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 raises an event. What happens is determined by statements inside the event procedure. 36

Sample Statements txtbox.forecolor = Color.Red txtbox.visible = True txtbox.text = "Hello World" General Form: controlname.property = setting 37

Sample Form txtfirst txtsecond btnred 38

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. 39

Examples of Events btnshow.click txtbox.textchanged txtbox.leave General Form: controlname.event 40

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. 41

Code Editor Code Editor tab Form Designer tab 42

Display Events for a Control Select the control Click on the Events button ( ) in the Properties window events button 43

Structure of an Event Procedure header Private Sub objectname_event(...) Handles objectname.event statements End Sub (...) is filled automatically with (ByVal sender As System.Object, ByVal e As System.EventArgs) 44

Create an Outline for an Event Procedure Double-click on a control or Select a control, click on the Events button in the Properties window, and double-click on an event (We nearly always use the first method.) 45

Sample Form txtfirst txtsecond btnred Double-click on txtfirst to create the outline for the Code Editor 46

Code for Walkthrough Public Class frmdemo Private Sub txtfirst_textchanged(...) Handles txtfirst.textchanged txtfirst.forecolor = Color.Blue End Sub End Class 47

IntelliSense Automatically pops up to help the programmer. txtfirst. 48

Code Editor click tab to return to Form Designer 49

Sample Form txtfirst txtsecond btnred Double-click on btnred to return to Code Editor and add the outline of an event procedure 50

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 51

Event Procedure txtfirst.leave Select txtfirst on the form Click on the Events button in the Properties window Double-click on Leave 52

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 53

Header of Event Procedure Private Sub btnred_click( ) Handles btnred.click Name, can be changed. Identifies event Private Sub Button_Press( ) Handles btnred.click 54

Handling Multiple Events An event procedure can be invoked by two events. Private Sub Happening(...) Handles btnred.click,txtsecond.leave txtfirst.forecolor = Color.Red End Sub 55

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" 56

Open and Run an Existing Program Click on Open Project in the File menu. Navigate to the program s folder. Double-click on the program s folder to open it. 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. 57