copyright 2003 : ismail m.romi, ppu. all rights reserved 1 lab2 managing controls
Post on 21-Dec-2015
216 views
TRANSCRIPT
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved
1
Lab2Lab2
Managing ControlsManaging Controls
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved
2
Controls (Tools)
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved
3
PropertiesSet of attributes for each object used in VB,
that changes the appearance and behavior of a Form or Control.
Properties Types:1- Design-time properties: properties than can
be changed at the design mode.
2- Run-time properties: properties that can be changed at the run-time.
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved
4
Common Properties for controls• See Table 3.1 page 65
• Notes:– The Form’s Name property
should be unique in the project.
– The Control’s Name property should be unique on the same form.
– Name property can be changed at the design mode only.
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved
5
The Form Object• The background window that the user see
during the program execution.
• The forms are given default names; Form1, From2…
• On the form you can place the controls from the toolbox required for the user interface.
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved
6
The Form’s Properties• See Page 68.
• Caption: The text that appears in from’s title bar..
• Icon: Displays an icon when the form is minimized.
• Picture: Image placed as a background to the form.
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved
7
Changing Form Properties at Run-Time• Syntax:
FormName.PropertyName = Value
• Examples:
Form1.Caption = “ Student Record”
Form1.Left = 0
Form1.MousePointer = vbHourglass
Form1.MousePointer = 11
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved
8
Form Events• Load: Occurs during loading the form into
main memory.
• Unload: Occurs when removing the form from main memory.
Note: You can find all form and other Control’s
events in the code window in the events ComboBox.
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved
9
The Pointer Tool
The pointer tool is not a control.
•This tool used to deselect any selected control in the toolbox.
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved
10
The Label Control • A control that displays uneditable text to the
user.
• This control used to:
1- Provide a heading or description on the form.
2- Identify another control.
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved
11
The Label Control Properties• Alignment: 0:Left, 1:right, 2:centered.
• Autosize: (True/False), adjusts the label control height and width to suit the text.
• Wordwrap: (True/False), to wrap the text into multiple lines.
• Font, Caption, Backcolor ……
Events: Click, Dbclick……...
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved
12
Changing Control Properties at Run-Time
Syntax:
FromName.ControlName.Property = Value
Example:
Form1.Label.Caption = “Student Name:”
Form1.Label.Alignment = 1 Right justify
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved
13
The Text Box Control A control used for accepting user input, and
displaying text at the run-time.
Properties:
MaxLength: determines the maximum number of characters.(0:open).
Multiline: (True/False), enables word wrap.
Scrollbars: (0:no, 1:Horizontal, 2:Vertical, 3:Both), enables the user to scroll the text. Scrollbars related with multiline.
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved
14
Text Box Properties ..[CONT]• Locked: True/False
• Passwordchar: Determines the character that appears when the user enters a text.
• Text: Specifies the initial text that appears in the text box.
Note: No caption property for text box
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved
15
Text Box Events• Change: Occurs when the vale of the text
property is modified.
• Keypress, Keydown, Keyup….
Focus: The currently selected control.
• Gotfocus Event: Occurs when the control have the focus.
• Lostfocus:
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved
16
Command Button ControlA control that represents a button. The user
press or clicks to initiate an action.
Properties
• Caption: Specifies the text that appears in the button.When you precede a letter with &, that letter becomes the accelerator key.
• Default: (True/False). True:the button activates when ever the user press
<Enter>. Note only one can have this value on the form
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved
17
Command Button Properties [CONT]• Cancel: The same as default property, but
the button activates when you press <ESC>.
• Style: (0:Standard, 1:Graphical). Specifies whether the command button displays text or picture.
• Picture: Specifies a graphical image that appears on the command button.
Note:Picture property depends on style property.
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved
18
Command Button Properties [CONT]• Value: Run-Time property
When you set the value of the command button to True, the command button’s Click Event activates.
Example:
Command1.Value = True
Events:Click, Dbclick……..
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved
19
Lab TrainingExample I :
Design a VB project to perform the following:– Accept two numbers in text boxes.– Add two command buttons: Add, End– When you click Add, the result of addintion
should appear in a label control.– When you click End the program end.
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved
20
Lab Training
QuestionsQ1: Design a VB project to:
– Add two TextBoxes to the form.– Add three command buttons (Check, Refresh,End).– Accept any two numbers in the textboxes.– When you click the Check command button the
greatest number should appear in a label control.– When you click Refresh, all data should be removed
from the controls.– When you click End the program end execution.
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved
21
Lab TrainingQ2: The following is the price list and discount
policy for the telephone calls:Call Type Unit Price Discount-UnitsInternal 0.5 First 100 units Between cities 1.2 3% of units more
that 300External 1.8 5% of the units which
exceeds 100 unit.
Design a VB project to calculate the Telephone invoice. The interface should be as follow:
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved
22
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved
23
Lab2 EndLab2 End