2-1 chapter 2 using vb.net to create a first solution

33
2-1 Chapter 2 Using VB .NET to Create a First Solution

Upload: kellie-sutton

Post on 16-Jan-2016

232 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 2-1 Chapter 2 Using VB.NET to Create a First Solution

2-1

Chapter 2

Using VB .NET to

Create a First Solution

Page 2: 2-1 Chapter 2 Using VB.NET to Create a First Solution

2-2

Learning Objectives

Begin using Visual Studio .Net and VB .Net Get familiar with the Microsoft Development

Environment (MDE) Learn to use of forms in VB .Net solutions Understand controls and their properties Learn to use message box

Page 3: 2-1 Chapter 2 Using VB.NET to Create a First Solution

2-3

Learning Objectives (continued)

Get familiar with Code Window to write event handlers

List types of files that make a VB .Net project Save an application code Learn to use help system

Page 4: 2-1 Chapter 2 Using VB.NET to Create a First Solution

2-4

The Microsoft Development Environment (MDE)

Start page– My Profile

Filter option

– New Project A number of types

– Windows application– Class library– Windows Control Library– …

Page 5: 2-1 Chapter 2 Using VB.NET to Create a First Solution

2-5

New Project Dialog Box

Page 6: 2-1 Chapter 2 Using VB.NET to Create a First Solution

2-6

The MDE Interface

Page 7: 2-1 Chapter 2 Using VB.NET to Create a First Solution

2-7

Key elements of the MDE (1)

Project title bar : shows name of project

Menu bar : lets the user choose actions

Toolbar : replicate commonly used menus

Windows buttons : provides instant access to key windows in the MDE

Page 8: 2-1 Chapter 2 Using VB.NET to Create a First Solution

2-8

Key elements of MDE (2)

Toolbox : contains user interface elements (controls) that are placed on forms

Design window : where you drop controls

Solution explorer : shows files for a project or solutions

Task List window : use it for a To Do list

Page 9: 2-1 Chapter 2 Using VB.NET to Create a First Solution

2-9

Setting Options for Development

Page 10: 2-1 Chapter 2 Using VB.NET to Create a First Solution

2-10

Solution Explorer Window

Displays all parts of a solution– The solutions file– The project file(s)– The classes, forms or modules

Button at top allows to switch between code and form display

Page 11: 2-1 Chapter 2 Using VB.NET to Create a First Solution

2-11

Properties window

Displays the properties for selected object

Allows access to properties at “design time”

Use combobox at the top to change the object

Page 12: 2-1 Chapter 2 Using VB.NET to Create a First Solution

2-12

Step-by-Step 2-1: Starting a project

Demo

Page 13: 2-1 Chapter 2 Using VB.NET to Create a First Solution

2-13

Form properties

Name : the name of the variable referring to the form in code (use a

name starting with frm to indicate it refers to a form object

Text : the caption in the title bar AcceptButton : the default button CancelButton : corresponds to Esc key

Page 14: 2-1 Chapter 2 Using VB.NET to Create a First Solution

2-14

Startup object

Page 15: 2-1 Chapter 2 Using VB.NET to Create a First Solution

2-15

Step-by-Step 2-2 Creating a form

Demo

Page 16: 2-1 Chapter 2 Using VB.NET to Create a First Solution

2-16

Adding controls to a form

To create the “visual” interface of application, click controls in toolbox and “draw” them on the form.

Types of controls Label PictureBox Button

Page 17: 2-1 Chapter 2 Using VB.NET to Create a First Solution

2-17

Label control

Used to display text programmatically User cannot change the text directly Properties

– Name (use lbl prefix)– Text– Font– Autosize– …

Page 18: 2-1 Chapter 2 Using VB.NET to Create a First Solution

2-18

PictureBox control

Used to display a picture Some Properties

– Name (use pic prefix)– Image– SizeMode

Normal StretchImage AutoSize CenterImage …

Page 19: 2-1 Chapter 2 Using VB.NET to Create a First Solution

2-19

Button control

The obvious place to click for some action! Some properties

– Name (use btn prefix)– Text– Font– ….

Page 20: 2-1 Chapter 2 Using VB.NET to Create a First Solution

2-20

Step-by-Step 2-3 Adding controls

Demo

Page 21: 2-1 Chapter 2 Using VB.NET to Create a First Solution

2-21

Adding code

Develop the logic for the action objects

Choose a control Double click on it Code window shows up with a stub for the event

procedure Choose the right event in methods List Box Write the code for the event handler

This is called an Event Procedure

Page 22: 2-1 Chapter 2 Using VB.NET to Create a First Solution

2-22

The Editor Window

Page 23: 2-1 Chapter 2 Using VB.NET to Create a First Solution

2-23

Simple use of MsgBox( )

It displays a message (the first argument) in a dialog box

Can accept more arguments to determine– Text in the title bar of dialog box– What icons are displayed in the dialog box– What buttons are available in the dialog box

Can return value indicating what button was clicked

Page 24: 2-1 Chapter 2 Using VB.NET to Create a First Solution

2-24

Testing code

Test run the application by– Clicking the Start button– Choosing menu Debug|Start– Pressing F5

You are now in Run Time

Page 25: 2-1 Chapter 2 Using VB.NET to Create a First Solution

2-25

Stop testing

You can stop by– Doing whatever will get your application to exit– Clicking the Stop button– Choosing Debug|Stop Debugging menu – Pressing Shift + F5

Page 26: 2-1 Chapter 2 Using VB.NET to Create a First Solution

2-26

Ste-by-Step 2-5: Adding code to button

Demo

Page 27: 2-1 Chapter 2 Using VB.NET to Create a First Solution

2-27

Files in VB .NET

Solution file (*.sln) Project file (*.vbproj) Form file (*.vb) Resource file (*.resx) AssemblyInvo.vb Folders

– Bin– Object

Page 28: 2-1 Chapter 2 Using VB.NET to Create a First Solution

2-28

Changing file names

For solution or project file– Right click in solution explorer– Select Rename option

For a form file– Use File menu– Save Form1.vb as … option

Page 29: 2-1 Chapter 2 Using VB.NET to Create a First Solution

2-29

Step-by-Step 2-6 Saving a project

Demo

Page 30: 2-1 Chapter 2 Using VB.NET to Create a First Solution

2-30

Using VB .NET Help

Four types of help Help menu option Dynamic help Web-based help Auto help

Page 31: 2-1 Chapter 2 Using VB.NET to Create a First Solution

2-31

Help menu Options

Dynamic Help Contents Index Search

Page 32: 2-1 Chapter 2 Using VB.NET to Create a First Solution

2-32

Step-by-Step 2-7 Using Help in VB .NET

Demo

Page 33: 2-1 Chapter 2 Using VB.NET to Create a First Solution

2-33

Copyright 2004 John Wiley & Sons, Inc.

All rights reserved. Reproduction or translation of this work beyond that permitted in section 117 of the 1976 United States Copyright Act without express permission of the copyright owner is unlawful. Request for further information should be addressed to the Permissions Department, John Wiley & Sons, Inc. The purchaser may make back-up copies for his/her own use only and not for distribution or resale. The Publisher assumes no responsibility for errors, omissions, or damages caused by the use of these programs or from the use of the information herein