Introducing more controls (on the Toolbox) (Fig. 2.1) - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

Introducing more controls (on the Toolbox) (Fig. 2.1)

Description:

create text box by 'Message' (user types a message at run time) ... Select multiple controls 'Draw' a box around the controls with the cursor or ... – PowerPoint PPT presentation

Number of Views:18
Avg rating:3.0/5.0
Slides: 20
Provided by: Tuc54
Learn more at: https://www.loyno.edu
Category:

less

Transcript and Presenter's Notes

Title: Introducing more controls (on the Toolbox) (Fig. 2.1)


1
More Controls
Introducing more controls (on the Toolbox) (Fig.
2.1) - Text box - Frame - Option button -
Check box - Image Example P. 44 Figure 2.2
Message formatter Text boxes The white box next
to Your Name The white box next to the words
Message Frame The box enclosing the Color
buttons The box enclosing the Style
buttons Option button The buttons labeled Red,
Green, Blue, Black. Check boxes The boxes
labeled Bold, Italic, and Underline. Image The
picture of the CD at the lower left.


2
Labels The label containing Your Name The box
containing Message The two blank boxes at the
bottom of the screen The label containing Click
Me Command buttons - Display, Clear, Print, Exit
Create the form in the book Create the
labels Create the label containing Your
Name - you need not change the Name - in
Properties change Caption to Your Name Create
the label containing Message - you need not
change the Name - in Properties change Caption
to Message Create one blank label at the
bottom center of the form - in Properties
change Name to lblMessage - in Properties
delete Caption
3
- create the label containing Click Me - you
need not change the Name - in Properties
change Caption to Click Me Note You need to
change the name of a label if you refer to the
label in the code i.e., if you place some
message in the label. Create the text boxes -
create text box by Name (user types a name at
run time) - create a Text box next to Your
Name - in Properties change Name to
txtName - in Properties delete the Text -
create text box by Message (user types a
message at run time) - create a Text box
next to Message - in Properties change Name
to txtMessage - in Properties delete the Text
4
- center the message in this box (this can be
done only at design time) - in
Properties set Multiline to True - in
Properties set Alignment to 2-Center Note The
Name of a text box begins with txt. Note A
label box has a Name and Caption. A text box has
a Name and Text. Example You can write
lblMessage.Caption txtMessage.Text in the
code. This places the message in the second text
box into the label box. (This will go into the
code for the Display button.) Create the frames
(for the Color and Style) A frame is a control
which contains several other controls.
5
- create the Color frame - in the Toolbox use
the Frame tool to draw a frame - in Properties
change Name to fraColor - in Properties change
Caption to Color - create the Style frame - in
the Toolbox use the Frame tool to draw a
frame - in Properties change Name to
fraStyle - in Properties change Caption to
Style Create the check boxes for Style - create
the check box for Bold - in the Toolbox use
the Check box tool to draw a check box within
the Style frame - in Properties change Name to
chkBold - in Properties change Caption to
Bold - create the check boxes for Italic and
Underline
6
Note you must draw the check boxes and option
buttons inside the appropriate frame you can not
create them and then drag them into the frame.
Place the Image onto the form The VB folder
contains several Images, which you can copy into
your form. Simply use Copy and Paste. - in
the Toolbox use the Image tool to draw a control
for the Image - in Properties change Name to
imgCDROM - copy in the picture - in Properties
select Picture (Fig. 2.3- 2.5) - find the
picture you want (the CD-ROM) - select Program
Files, Dev Studio, VB, Graphics, Icons,
Computer, CDROM
7
- double-click on the image - copy in the
other picture - create a new Image frame -
copy the other image into the frame - when both
pictures are on the frame, drag one image
frame on top of the other Note copying one
picture on top of another will hide one of the
pictures. In the code we will see how to show
each of the pictures alternately. - set other
properties - enlarge the image - resize the
Image control - in Properties set Stretch to
True - hide the picture - set Visible to
False (in the code)
8
- giving a 3-dimensional appearance to
controls - in Properties select Borderstyle to
1 - 3D - in Properties select Appearance and
1-3D Working with multiple controls Select
multiple controls Draw a box around the
controls with the cursor or hold the Shift key
and click on the controls Deselecting a group of
controls Click outside the selected group Moving
controls as a group Click and drag Setting
properties for multiple controls Align controls
9
Setting properties for user convenience Defining
keyboard access keys (for command buttons,
option buttons, and check boxes) - in
Properties put the symbol before a letter in
the Caption for a command button - the letter
will appear underlined on the form - the user
can hit Alt and that letter to activate the
command Example In the message formatter there
is an underline under R in the word Red. If the
user hits Alt R, then the message appears
red. Setting the default and cancel properties
Default - in Properties set Default to True -
user activates this button with Return Cancel -
in Properties set Cancel to True - user
activates this button with Esc
10
Set the tab order for controls - in Properties
select Tabindex - type in a number indicating
the order in which you want the control to be
chosen when the program runs - Example In
Properties set Tabindex to 4. When you run the
program, if you hit the Tab key, this control
will be the fourth one to be activated.
Coding for the controls Clearing text boxes
and labels (in code) - text box - set the
Text to - Example txtName.text
-label - set the Caption to - Example
lblMessage.Caption
11
Resetting the focus Definition The focus is the
control which holds the cursor when the program
starts. Example To set the focus in the Name
text box, the command is txtName.SetFocus. (In
the Text formatter, this command occurs in the
code for the Clear control.) Setting the value
properties of option buttons and check boxes (in
code) Example Check the Red option button
optRed.ValueTrue Example Check the Bold check
box chkBold.Value 1 OR chkBold.Value
Checked Example Uncheck the Bold check
box chkBold.Value 0 OR chkBold.Value
Unchecked
12
Changing the font properties of controls -
before running the program - in Properties
select Font - in the dialogue box check the
desired properties - in code - assign the
appropriate font property and value -Example
txtName.Font.Bold True lblMessage.Font.Si
ze 12 lblTitle.Font.Italic True Changing
the color of text (in code) - set the ForeColor
to one of the color constants vbBlack, vbRed,
etc. (see P. 55)
13
Changing multiple properties of a control
Example Book P. 56 The code txtTitle.Visible
True txtTitle.ForeColor vbWhite txtTitle.Fon
t.Bold True txtTitle.Font.Italic
True txtTitle.SetFocus can be rewritten as With
txtTitle .Visible True .ForeColor
vbWhite End With Concatenating text Use the
symbol Example lblMessage.Caption Hello
txtMessage.text
14
Continuing program lines Use _ Example
lblMessage.Caption If you return the winning
number, _ txtName.text , you will be
rich! Using the value of controls Example
lblMessage.Caption txtName.text
15
Objects, Methods, and Properties Option button
Red
Properties Name optRed Caption Red gt
Value True Method optRed_Click ()
User
16
Check box
Bold
Properties Name chkBold Caption Bold
gt Value Checked Method chkBold_Click ()
User
17
Command button
Display
Properties Name cmdDisplay Caption Display Meth
od gt cmdDisplay
User
18
Label
Your name
Properties Name lblName Caption Your Name
User lt
19
Text box
Properties Name txtName gt Text
User
Write a Comment
User Comments (0)
About PowerShow.com