Visual Basic - منتديات طلاب وطالبات

download report

Transcript Visual Basic - منتديات طلاب وطالبات

CpCS 206
Instructors: Sidra Ehsan
Badoor Bawazeer
Visual Basic 2005
2
Visual Basic 2005

3
Visual Basic has three modes in which it operates:
◦ Design Mode
 The mode in which you create the application
 Also known as design time
◦ Run Mode
 Executes the application in the visual studio
environment
 Also known as run time
◦ Break Mode
 Momentarily suspends execution of a running
application
 For testing and debugging purposes
Visual Basic 2005
4
Visual Basic 2005
5
Visual Basic 2005
Default location is
My Documents\Visual Studio Projects\Projects
6
Visual Basic 2005

User creates a new project in Visual Studio
◦ A solution and a folder are created at the same
time with the same name as the project
◦ The project belongs to the solution
◦ Multiple projects can be included in a solution

The folder stores files related to the project
including:
◦ A solution file (.sln)
◦ A project file (.vbproj)
Visual Basic 2005
Project is saved automatically in the default
folder with the folder name you typed in the
Name textbox.
All of files for your first project are then saved
in this folder.
8
Visual Basic 2005

Use Recent Projects list on Start Page
◦ Provided it hasn’t been moved or deleted

Use Open Project button on Start Page
◦ Then browse using Open Project dialog box

Use Open Project option on File menu
◦ Then browse using Open Project dialog box
Visual Basic 2005



This window contains all the configurable
options for components and controls.
The
properties
window
displays
the
properties for only the currently selected
component or control.
Different properties are available for different
controls.
Visual Basic 2005


Used to view and modify the property values
of a given object.
Two views of the properties are available:
◦ Alphabetic (across all properties)
◦ Categorized (groups properties by logical use)
Visual Basic 2005
12
Visual Basic 2005


It illustrates the contents of the open
solution. The contents are presented in a
hierarchical collapsible tree.
You can use the solution explorer
window to:
◦ Manage the projects in your solution
◦ Mange the references to projects
◦ Manage solution trees
Visual Basic 2005
14
Visual Basic 2005
There are seven categories
of tools available.
To see the tools, click on
the plus symbol next to
Common Controls.
15
Visual Basic 2005
16
Visual Basic 2005
Do the following:
 Locate the TextBox tool
 Double click the icon
 A textbox is added to your form
The textbox gets added to the top left position of
your form. To move it down, hold your mouse over
the textbox and drag to a new position:
17
Visual Basic 2005
Design Mode
 Locate the Label control in the toolbox
 Double click the label icon
 A new label is added to your form
 It should look like the one below
18
Visual Basic 2005
Design Mode
 Locate the Button control in the toolbox
 Double click the Button icon
 A new button is added to your form
 It should look like the one below
19
Visual Basic 2005

20
Click Debug > Start from the menu bar.
Or
press F5 on your keyboard
Visual Basic 2005
1. Click Debug > Stop Debugging
from the menu bar
2. Press Shift + F5 on your keyboard
21
Visual Basic 2005

To print a project’s code:
◦ open the Code window
◦ click File on the menu bar
◦ click on the Print command

Using the keyboard shortcut:
◦ open the Code Window
◦ Ctrl + P to print
22
Visual Basic 2005
23
Visual Basic 2005
24
Visual Basic 2005

Window Tabs

Solution Explorer Icons

Menu Bar

Keyboard Shortcuts
◦ F7 opens the Code Window
◦ Shift + F7 opens the Designer Window
25
Visual Basic 2005

Border style properties for a form:
◦ Sizable: (Default) Has min, max, and close
buttons; can be resized by dragging edges
◦ Fixed3D: Has a 3D look; min, max, and
close buttons; cannot be resized
◦ FixedSingle: Has single line border; min,
max, and close buttons; cannot be resized
26
Visual Basic 2005


Locking controls prevents them from being
moved around during design time
To Lock Controls:
◦ right-click an empty space on the form
◦ select Lock Controls from the menu

To Unlock Controls:
◦ right-click an empty space on the form
◦ select Lock Controls from the menu

Control Locking has a Toggle Effect:
◦ Follow the same steps to lock/unlock controls
27
Visual Basic 2005



28
AutoSize is a Boolean (either True or False)
Property of labels
False (the default) means the box size will not
change, regardless of the amount of text
assigned to it
True means the box will automatically resize
itself to fit the amount of text assigned to it
Visual Basic 2005

29
The value of TextAlign establishes the
alignment (or justification) of the text:
Code for TextAlign is
lblReportTitle.TextAlign = ContentAlignment.MiddleCenter
Visual Basic 2005


IntelliSense is a feature that provides
automatic code completion as you type
programming statements
Press the Tab key to use IntelliSense
◦ For Example:
30
Visual Basic 2005
You can use the MessageBox.Show method to
display a message box, which is a dialog box that
pops up, showing a message to the user.
31
Visual Basic 2005

A message box is
◦
◦
◦
◦

a small window
sometimes referred to as a dialog box
a convenient way to display output to the user
displayed until the OK button is clicked
For example:
MessageBox.Show("Hello World!")
MessageBox
32
dot
Show
string “Message”
enclosed in
parentheses
Visual Basic 2005
33
Visual Basic 2005

You access the Visual Studio Documentation
and the MSDN library by clicking Help on the
menu bar.
34
Visual Basic 2005


Displays information about whatever feature
the user is currently focused on
For example:
◦
◦
◦
◦
◦
◦
35
Click on a Button control
Press F1
Help explains all about the Button control
Click on a Label control
Press F1
Help explains all about the Label control
Visual Basic 2005
At some point, most applications contain bugs
(errors) that prevent the application from operating
properly. In this section, you learn fundamental
debugging techniques.
36
Visual Basic 2005





37
These are errors in the syntax (form) of your
program
Visual Basic will inform you of these errors as
soon as the code is entered
The area of the error will be underlined with a
jagged blue line
A description of the error will be given in the
Error List window
Display this window by selecting Error List
from the View menu option
Visual Basic 2005



38
Some errors occur as your program runs
These are different from syntax errors which
occur as the code is entered by the
programmer
Runtime errors occur when Visual Basic
attempts to perform an operation that cannot
be executed
Visual Basic 2005
39
Visual Basic 2005
Create an application that logins the User.
40
Visual Basic 2005
Purpose: To login the user
Input: User Name and Password
Process: Check User Name and Password,
Then login the user
Output: Successful Login Message Box
41
Visual Basic 2005
Visualized Interface
42
Visual Basic 2005
Control Type
Control Name
Description
Form
Form1
(Default Name)
A small form that will serve as
the window onto which the other
controls will be placed
Label
Label1
(Default Name)
Displays the message
“User Name“
Label
Label2
(Default Name)
Displays the message
“Password"
Textbox
TextBox1
Allows the user to enter the User Name
(Default Name)
Textbox
TextBox2
PictureBox
(Default Name)
PictureBox1
(Default Name)
43
Allows the user to enter the Password
Displays the graphic image
Visual Basic 2005
Control Type
Control Name
Description
Button
Button1
(Default Name)
When clicked, login the user if user will be
admin and password will be 123456
Button
Button2
(Default Name)
When clicked, Exit the Login Form
44
Visual Basic 2005
Establish the Form and set its Text property
1. Form
Name: frmLogin
Text: Login Form
BackColor :Any Color except White
2. Label control
Name: lbl……
Text: Required Text
Font :Microsoft Sans Serif, Bold, 9 Size
Fore Color: Medium Blue
Text Align: MiddleCenter
Visible: True
45
Visual Basic 2005
3. TextBox
Name: txt……
Text: Required Text
Font :Microsoft Sans Serif, Bold, 9 Size
Fore Color: Medium Blue
Text Align: MiddleCenter
Visible: True
4. Button control
Name: btn……
Text: Required Text
Font :Microsoft Sans Serif, Bold, 9 Size
Fore Color: Medium Blue
Text Align: MiddleCenter
Locked: True
46
Visual Basic 2005
5. Picture
Name: PictureBox1
Picture: PictureName.jpg
SizeMode: Zoom
Visible: True
Locked: True
47
Visual Basic 2005
48
Visual Basic 2005
If txtUserName.Text = "admin" And txtPassword.Text = "123456" Then
MessageBox.Show("Login Succesfull")
Me.close()
49
Visual Basic 2005
Add the following property for lblPassword
PasswordChar: type any symbol (for hidden characters)
50
Visual Basic 2005
1. Establish the Form and set its Text property
2. Add Label controls
3. Add TextBox controls
4. Add Button controls
5. Add a PictureBox control
6.Run the application
7. Close and save the application
51