You are on page 1of 24

Section 2: An Introduction to Visual

Basic .NET

Input box

Public Class Form1

Private Sub Form1_Load(ByVal sender As


System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
Dim userName As String = Nothing
userName = InputBox("what is your name?",
"hello", , , )
Label1.Text = "Hello," & userName
End Sub
End Class

Creating a Windows-Based Application in


Visual Basic .NET
section objectives

Start and customize Visual Studio.NET

Create a Visual Basic .NET project

Add an object.

Set the properties of an object

Starting and Customizing


Visual Studio .NET

Visual Studio .NET is Microsofts integrated


development environment (IDE)

Includes programming languages such as Visual


Basic .NET, C++ .NET, and C# .NET

A Windows-based application has a Windows user


interface and runs on a desktop computer

A user interface is what you see and interact with


when using an application

A Web-based application has a Web user interface


and runs on a server

Starting and Customizing


Visual Studio .NET (continued)

Windows in the Visual Studio .NET IDE:


Start

Page

Solution
Server

Explorer

Explorer

Toolbox
Class

View

Dynamic

Help
5

Starting and Customizing


Visual Basic .NET

Figure 1: Projects pane in the Start Page window6

Creating a Windows-Based
Application

A project is a container that stores files


associated with only a specific piece of
the solution

Creating Form 1 (continued)

Figure 2: New Visual Basic .NET

The Windows Form Designer


Window

Windows Form Designer window is where


you create (or design) the graphical user
interface (GUI) for your project

You create the user interface by adding


other objects (such as buttons and text
boxes) to a Windows Form object (or
form)

The Windows Form Designer


Window (continued)

Figure 3: Windows Form Designer window )


(
10

The Properties Window

Each object has a set of attributes, called


properties, that determine its appearance
and behavior

The Properties window exposes the


objects properties to the programmer

The Properties window includes an Object


box and a Properties list

The Properties window can be used to


change a property of an object
11

The Properties Window


(continued)

Figure 4: Properties window showing the properties of the


Form1.vb file object
12

Properties of the Windows


Form Object

The Windows Form object has a set of


properties

Properties of the Windows Form object


will appear in the Properties window
when you select the Windows Form object
in the designer window

13

Properties of the Windows


Form Object (continued)

Important properties of the Windows


Form object:

Name property

Text property

StartPosition property

Size property

BackgroundImage property

14

Working with Controls

Add a control to a form

Set the properties of a label, picture box, and button


control

Select multiple controls

Center controls on the form

Set the properties of a project

15

The Toolbox Window

The Toolbox window, or toolbox, contains the tools


and other components you use when designing a
user interface

Tools in the toolbox allow you to create objects,


called controls, that can be displayed on a form

16

The Toolbox Window


(continued)

The Windows Form tab

Contains the tools you use when designing


your user interface

Contains 47 basic tools

You can add new tools or delete existing


tools

By default, the tools on the Windows Form


tab are listed in order by their estimated
frequency of use, with the most used tools
listed first
17

Using the Button Tool

Every Windows application should give


the user a way to exit the program
Most

Windows applications provide


either an Exit option on a File menu or
an Exit button for this purpose

In Windows applications, a button control


performs an immediate action when
clicked

You create a button using the Button tool


in the toolbox
18

Task to do:
Private Sub Button1_Click_1(ByVal sender As
System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
MessageBox.Show("Hello World", "First Window")
End Sub
End Class

19

Test question 1
In Visual Basic, we work with objects that have _______.

A) Programmer preference
B) Projects, solutions, and procedures
C) Classes, actions, and disciplines
D) Properties, methods, and events

Test question 2
If you want to display text that cannot be modified by the
user, use the _______.
A)
B)
C)
D)

TextBox control
Label control
Caption control
MaskedTextBox control

21

Test question 3
If you want to display text that can be modified by the user,
use the _______.
A)
B)
C)
D)

TextBox control
Label control
Caption control
MaskedTextBox control

22

Test question 4
Assume that you are designing a form and it will be
necessary for the user to type in his name. You should
use a _____________ for inputting the user's name
A)
B)
C)
D)

Textbox
Label
Button
CheckBox

23

Input box
Public Class Form1

Private Sub Form1_Load(ByVal sender As


System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
Dim userName As String = Nothing

userName = InputBox("what is your name?",


"hello", , , )
Label1.Text = "Hello," & userName
End Sub
End Class
24