2-1 chapter 2 using vb.net to create a first solution
TRANSCRIPT
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
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
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– …
2-5
New Project Dialog Box
2-6
The MDE Interface
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
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
2-9
Setting Options for Development
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
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
2-12
Step-by-Step 2-1: Starting a project
Demo
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
2-14
Startup object
2-15
Step-by-Step 2-2 Creating a form
Demo
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
2-17
Label control
Used to display text programmatically User cannot change the text directly Properties
– Name (use lbl prefix)– Text– Font– Autosize– …
2-18
PictureBox control
Used to display a picture Some Properties
– Name (use pic prefix)– Image– SizeMode
Normal StretchImage AutoSize CenterImage …
2-19
Button control
The obvious place to click for some action! Some properties
– Name (use btn prefix)– Text– Font– ….
2-20
Step-by-Step 2-3 Adding controls
Demo
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
2-22
The Editor Window
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
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
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
2-26
Ste-by-Step 2-5: Adding code to button
Demo
2-27
Files in VB .NET
Solution file (*.sln) Project file (*.vbproj) Form file (*.vb) Resource file (*.resx) AssemblyInvo.vb Folders
– Bin– Object
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
2-29
Step-by-Step 2-6 Saving a project
Demo
2-30
Using VB .NET Help
Four types of help Help menu option Dynamic help Web-based help Auto help
2-31
Help menu Options
Dynamic Help Contents Index Search
2-32
Step-by-Step 2-7 Using Help in VB .NET
Demo
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