Pemograman Visual
Pertemuan 3 - Control
Visual Basic Controls
• Starting a New Visual Basic Program
• Text Box Control
• Button Control
• Label Control
• List Box Control
• Name Property
• Fonts / Auto Hide
• Positioning and Aligning Controls
2
Visual Basic Start Page
3
Start a New Project
4
New Project Dialog Box
select
click on OK button
5
Initial Visual Basic Screen
6
Toolbox
7
4 Ways to Place a Control from the
Toolbox onto the Form Designer
• Double-click
• Drag and Drop
• Click, Point, and Click
• Click, Point, and Drag
8
Four Controls at Design Time
text box
To select a control, click on it. Sizing handles
will appear when a control is selected. 9
Text Box Control
• Used for input and output
• When used for output, ReadOnly property
is set to True
Tasks button
sizing handles
10
Label and Textbox
• Textbox Properties
• PasswordChar
• Multiline
• ScrollBards
• ReadOnly
Properties Window
Press F4 to
display the
Properties
window for
the selected
control.
categorized view alphabetical view 12
Properties Window (continued)
selected
control
properties settings
Description
13
pane
Some Often Used Properties
• Text
• Autosize
• Font.Name
• Font.Size
• ForeColor
• BackColor
• ReadOnly
14
Setting Properties
• Click on property name in left column.
• Enter its setting into right column by typing or selecting from
options displayed via a button or ellipses.
15
Setting the ForeColor Property
1. Click on ForeColor.
2. Click on button at
right of settings box.
3. Click on Custom tab
to obtain display
shown.
4. Click on a color.
16
Font Property
1. Click on Font
in left column.
2. Click on
ellipsis at right
of settings box
to obtain
display shown.
3. Make
selections. 17
Button
• Properties
• Name
• Text
• Image
• ImageAlign
• TextAlign
Button
• Use AcceptButton property
in Form Control to trigger
Enter Keyboard
Button
• Use AcceptButton property
in Form Control to trigger
Enter Keyboard
Button
• The message Smile will show when user press the enter button
Button Control
• The caption on the button should indicate the effect
of clicking on the button.
Text
property
22
Add an Access Key
23
Label Control
• Used to identify the contents of a text box.
• Text property specifies caption.
• By default, label automatically resizes to accommodate
caption on one line.
• When the AutoSize property is set to False, label can be
resized manually. AutoSize is used primarily to obtain a
multi-rowed label.
24
List Box Control
• Initially used to display several pieces of output.
• In Chapter 4 used to select from a list.
25
Checkbox and Radio Button
Combo Box
ListBox
Checked Listbox
The Name Property
• Used by the programmer to refer to a control in code
• Setting for Name property near top of Properties
window
• Use appropriate 3-character naming prefix
• Use descriptive names
30
Control Name Prefixes
Control Prefix Example
button btn btnCompute
label lbl lblAddress
text box txt txtAddress
list box lst lstOutput
31
Renaming the Form
• Initial name is Form1
• The Solution Explorer window lists a file named
Form1.vb.
• To rename the form, change the name of this file to
newName.vb
• newName should begin with prefix frm.
32
Fonts
• Proportional width fonts, such as Microsoft Sans
Serif, use less space for "I" than for "W"
• Fixed-width fonts take up the same amount of
space for each character – like Courier New
• Fixed-width fonts are used for tables.
33
Auto Hide
• Hides Toolbox when not in use
• Vertical push pin icon indicates auto hide is
disabled.
• Click the push pin to make it horizontal and enable
auto hide.
push pin
34
Positioning Controls
proximity
line
35
Aligning Bottoms of Controls
snap line
36
Aligning Middles of Controls
snap line
37
Tab Order
The tab indices
determine the order in
which controls receive
the focus during tabbing.
The control whose
TabIndex property is set
to 0 has the focus when
the program begins. 38
Menus
Menus
Context Menus