Word Document Properties


Part II: Learning the Ropes



Download 8,82 Mb.
Pdf ko'rish
bet139/207
Sana16.03.2022
Hajmi8,82 Mb.
#496217
1   ...   135   136   137   138   139   140   141   142   ...   207
Bog'liq
VBA For Dummies 5th Ed.pdf ( PDFDrive )

Part II: Learning the Ropes 
12_046500 ch07.qxp 12/5/06 5:35 PM Page 158


Adding controls to the form
Before you can add controls to a form, you need a form. Right-click any-
where in the Project Explorer window and then choose Insert

UserForm
from the context menu that appears. After you add the form, make sure that
you give it an easily remembered name by changing the 
Name
property in
the Properties window. Use the 
Caption
property to change the text on the 
title bar.
The easiest and least error-prone method of adding a control to a form is to
select the control in the Toolbox and then click the area of the form where
you want the control to appear. The mouse cursor points to the upper-left
corner of the control. The cross cursor makes it easy to place the control
accurately. You might need to organize the controls after you add them
because it isn’t easy to add the controls precisely. See the upcoming
“Making your form pretty” section for details.
Another method for adding controls to a form is to drag the control from
the Toolbox and then drop it on the form. The reason why this method is 
less precise is that you don’t always see the control’s location. The IDE dis-
plays a box showing the outline of the control, so you do see the basic layout
when using this method.
OptionButton
ListBox
TextBox
ComboBox
Label
CheckBox
Select
Objects
SpinButton
MultiPage
TabStrip
ScrollBar
Image
CommandButton
ToggleButton
RefEdit
Frame
Figure 7-2:
VBA pro-
vides a
useful set of
controls that
meet most
needs.
159
Chapter 7: Interacting with the User
12_046500 ch07.qxp 12/5/06 5:35 PM Page 159


Understanding the two parts of a form
Forms, and the controls they hold, provide the visual portion of a user inter-
face. This is the part of the form interface that the user sees, but it isn’t much
good without some code. You need code to tell VBA what to do when the
user interacts with the form. Any user interaction is an 
event,
and the code
you build is an 
event handler.
Consequently, when you create a form, you
work with two windows. The first is a UserForm window, where you address
the visual elements; the second is the Code window, where you add code to
handle user events, such as clicking a command button.
When you add a new form to an application, the Visual Basic Editor opens
the UserForm window immediately and displays the Toolbox so that you can
add controls. However, it doesn’t display the Code window. You can use any
of the following techniques to open the Code window:
Choose View

Code or press F7.
Right-click the UserForm entry in Project Explorer and choose View
Code from the context menu.
Right-click the control you want to work with and choose View Code from
the context menu.
The last option on the list not only displays the Code window but also creates
a handler for the default event for that control. All standard VBA controls have
a default event. For example, the 
CommandButton
control uses the 
Click
event, which occurs when the user clicks the command button. Even the form
has a default event
Click
, so this last option always results in the creation
of an event handler. The default event depends on the action that the user is
most likely to perform. See the later “Handling form events” section of this
chapter for more information about events.
Using the Label control to display text
You use the 
Label
control to display text onscreen. A 
Label
is for informa-
tional purposes. Although you can copy the content of a 
Label
, you can’t
change it directly. The most common use for labels is to identify other controls
and to provide accelerator key access to them. (See the upcoming “Modifying
the form and control properties” section of this chapter for details on adding
an accelerator key.) Labels also act as output for read-only text.
Figure 7-3 shows a simple form with two labels. The first label has 
Message
Text
in the 
Caption
property. The label uses 
M
as the 
Accelerator
prop-
erty value, so the M in Message Text is underlined. When you press Alt+M,
VBA selects the 
TextBox
control associated with the first label.
160

Download 8,82 Mb.

Do'stlaringiz bilan baham:
1   ...   135   136   137   138   139   140   141   142   ...   207




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish