Vous êtes sur la page 1sur 29

DEPARTMENT OF TECHNICAL EDUCATION

NDHRA PRADESH
Name of the faculty : G. Radha
Designation : Lecturer
Branch : CCP
Institute : SG Govt. Polytechnic, Adilabad
Year / Semester : V Semester
Subject : Visual Basic – I
Subject Code : CCP - 503
Topic : Understand designing the user
Interface
Duration : 50 Mts.
Sub Topic : Understand the designing aspects
of VB Forms
Teaching Aids : Animations & Images

CCP-503.5 1
Objective:

On completion of this period, you would be able to

 Design VB forms
Recap

In the previous period we have discussed


about

 Help System in VB
 Saving, Debugging and Distributing of VB
Application

CCP-503.5 3
Following points will be covered
in this Period

 Designing aspects of VB Forms

CCP-503.5 4
Designing aspects of VB Form
Any Visual Basic application is developed by using the
following steps
 Creating the user interface in VB
 Setting properties of the elements of user
interface
 Writing code by using Methods and Events of the
elements
 Running the application

CCP-503.5 5
Creating the Interface
 The interface is that part of the application which
is visible to user
 VB makes it easy to create a user interface by
simply dragging controls onto a form
 User is not aware of the code that is executing
behind the interface.

CCP-503.5 6
Form control
 Form is one of the most basic object in which
application is developed
 A Form is a window that contains the
application code
 Other objects are placed on the form to
create the user interface
Drawing a Control on a Form
We can draw a control on a form in two
ways.
Method1:
 Double click on the control in the tool box.
 Automatically the control will be placed at
the centre of the form.
 Resize and place it at the required place on
the form.
Drawing a Control on a Form

Method2:

 Click on the tool for the control you want to draw -


text box, command button, etc..
 Move the pointer onto your Form. The pointer
becomes a cross hair
 Place the cross hair where you want
 Drag the cross hair until the control becomes the
size you want
 Release the Mouse button

CCP-503.5 9
Setting Properties

 Properties define the characteristics of an object


such as size, color etc.,
 Each element in VB like Form, Textbox, Label
etc., has its own properties
 The properties of a control can be set using the
properties window, which can be displayed by
pressing F4 function key or right clicking on the
object.

CCP-503.5 10
Properties Window

CCP-503.5 11
Writing Code

 The essence of a Microsoft windows program is to


make the forms responsive to the user actions
 Visual Basic objects can recognize many different
methods & events
 VB programs are built around events using methods

CCP-503.5 12
Methods
 Methods are the actions that can be carried out
by objects.
 Some methods are simple verbs that tell the
object the action to carry out.
 Eg. Clear, move, Additem, Removeitem etc.,
Events
 Event determine the control’s reactions to external
conditions
 Controls recognise events, but our application handles
them.
 For example a command button recognise that it was
clicked, but it won’t react to the event unless we
provide some code.
 Eg. Click, DblClick, GotFocus, SetFocus etc.
 Events are various things that can happen in a
program. For ex. Textbox control events such as
Change, Click etc..
Code Window Dialogue Box
VB programs are written in code window
To open the code window Double Click in any part
of Form or Control

CCP-503.5 15
Code Window Dialogue Box

 Contains two combo boxes in the top screen


marked as Object and Procedure
 Object box displays names of the selected objects
and controls
 Procedure box lists all the events that the VB object
named in the Object box can recognize
 Code in a VB application is divided into similar
blocks called Procedures

CCP-503.5 16
Running the Application

 To run the application, choose Start from the


Run Menu or press F5 function key or click on
Arrow Mark on the Standard Tool Bar

CCP-503.5 17
Code Writing Example

 Open a new Standard-Exe Project in design


mode. Now switch to the properties windows and
change the name property of the Form as
‘Test_Form’, and also change the caption
property as ‘Designing of the Form’
 Place a text box on the Form and change its text
property to <Empty>

CCP-503.5 18
Code Writing Example (Contd..)

 Place two command buttons on Form and


change the name properties of Command1 as
‘cmdDisplay’ and ‘cmdExit’ respectively. Also
Caption property of Command1 as ‘Display’
and Caption property of Command2 as ‘Exit’
 Type the following code in cmdDisplay – Click()
event between the Sub and End Sub
statements :

CCP-503.5 19
Code Writing Example (Contd..)
 Private Sub cmdDisplay_Click()
Text1.text = “Hello, Welcome to VB Environment”
End Sub
 Type the following code in cmdExit_Click() event
between the Sub and End Sub statements
 Private Sub cmdExit_Click()
End
End Sub
 To run the application click Run Menu ->Start or
F5 Function Key or Arrow Mark on the
Standard Tool Bar
CCP-503.5 20
Sample Form Lay Out

CCP-503.5 21
Sample Code for cmd Display
Command Button

CCP-503.5 22
Sample Code for cmd Exit
Command Button

CCP-503.5 23
Screen After Running the Program

CCP-503.5 24
Summary

We have discussed about :

 The designing aspects of VB Forms

CCP-503.5 25
Quiz

CCP-503.5 26
1. To run VB application which of the
following Function key is pressed ?
A. F1
B. F4
C. F5
D. F3

CCP-503.5 27
2. To change the name of Form what is to be changed ?
A. Form Property
B. Form Event
C. Form Procedure
D. Caption property

CCP-503.5 28
Frequently Asked Questions

1. Explain the procedure for developing


application in VB.
2. Define method? Give any four examples.
3. What is an event? List any four events.

CCP-503.5 29

Vous aimerez peut-être aussi