|
|
frmWord |
|||||||||||
|
txtWord |
|||||||||||
|
fraFontName
|
|||||||||||
|
fraFontStyle
|
|||||||||||
|
lblFontSizeLabel |
|||||||||||
|
lblFontSize |
|||||||||||
|
hspFontSize |
|||||||||||
|
cmdClear |
|||||||||||
|
cmdEnd
Word Processor .01 Step by Step |
![]()
We want the user to be able to select a font size between 6 and 22 points. The initial value should be 14 (half way between). We must always display the current font size in lblFontSize.
Set the following properties at design time:
hsbFontSize
|
value = 14 |
|
|
min = 6 |
|
|
max = 22 |
|
|
smallchange = 4 |
|
|
largechange = 4 You must also put the initial value of the scroll bar (14) in the label (lblFontSize.Caption) lblFontSize |
|
|
Caption = 14 |
|
|
Alignment = Center (looks prettier!) |
The code behind the horizontal scroll bar does 2 things- first it changes the fontsize property of the text box (txtText) to the value of the horizontal scroll bar. Second, it changes the caption property of the label (lblFontSize) to the value of the horizontal scroll bar. The code goes in the Change event, which occurs whenever the value of the scroll bar changes. The psuedocode is:
let the font size of the text box = the value of the scroll bar
let the caption property of the label = the value of the scroll bar
You should also be able to program the Clear button (Let the text property of the text box = nothing! (nothing = "") and the Exit button (Unload Me).
Test and debug your program. Type some text in the text box and move the scroll bar. The text should change size and the label should reflect the new size.
![]()
The option buttons control the font that is displayed in the text window. Option buttons are used because only one font can be selected. Since. by definition, only one option button is selected, the code is straightforward. Just send the text box a message saying "Change your font name to ----"
txtWord.FontName = "MS Sans Serif"
A word of caution-- spelling counts! (You must have the name of the font exactly the same as the font name on the system. Simply click on the Font property of any object to see the possibilities!) The other two option buttons have similar code. Note that the event we are programming is called "click" just like a button!)
Also note that the default font for the text box is MS Sans Serif. Therefore, the Sans Serif option button should have its value property changed to True. This will make it the default button when you run the program.
![]()
The check boxes are used to allow the user to select from several font styles, namely bold, italics, and/or underline. Check boxes are used because the user may select any number of the choices (unlike radio buttons where you may select one and only one!) When you check a box that is "on" it turns "off" and visa versa. This means that your code must check to see if the box is being selected or "unselected." For example, for chkFontBold-
If (the fontbold property of the text box is True) Then
make it false
Else
make it try
in Visual Basic:
If (txtWord.FontBold = True) Then
txtWord.FontBold = False
Else
txtWord.FontBold = True
End If
The other check boxes work in a similar manner.
![]()