ID Number: Q81220
1.00
WINDOWS
Summary:
The text box control in Visual Basic displays the entire text box with
either FontUnderline, FontBold, FontItalic, or FontStrikethru, but with
only one font at once. This behavior is by design.
However, you may want to display a box with all four fonts at the same
time with separate words displayed in different fonts. Below is an
example of displaying the fonts FontBold, FontItalic, FontStrikethru,
and FontUnderline in a picture box control in Visual Basic to work
around the limitation in text boxes.
More Information:
The example below is one way of simulating a text box's contents in a
variety of fonts.
1. Run Visual Basic, or from the File menu, choose New Project (ALT,
F, N) if Visual Basic is already running. Form1 is created by
default.
2. Place a picture box on Form1, and double-click on the picture box
to open the Code window. Add the following code the the Click
event. Notice that the font properties are a Boolean type (that is,
-1 = True and 0 = False).
Sub Picture1_Click ( )
'** the word "Hello, " will be in FontBold
temp$ = "Hello, "
Picture1.FontBold = -1
Picture1.FontItalic = 0
Picture1.FontStrikethru = 0
Picture1.FontUnderline = 0
Picture1.Print temp$
'** need to program the next location to print in FontItalic
Picture1.Currentx = 500
Picture1.Currenty = 0
Picture1.FontBold = 0
Picture1.FontItalic = -1
Picture1.FontStrikethru = 0
Picture1.FontUnderline = 0
temp$ = " there!"
Picture1.Print temp$
'** need to program location to print in FontStrikethru
Picture1.Currentx = 1100
Picture1.Currenty = 0
Picture1.FontBold = 0
Picture1.FontItalic = 0
Picture1.FontUnderline = 0
Picture1.FontStrikethru = -1
temp$ = "This"
Picture1.Print temp$
'** need to program location to print in FontUnderline
Picture1.Currentx = 0
Picture1.Currenty = 200
Picture1.FontBold = 0
Picture1.FontItalic = 0
Picture1.FontStrikethru = 0
Picture1.FontUnderline = -1
temp$ = "is a test."
Picture1.Print temp$
End Sub
Notice that the CurrentX and CurrentY properties are used to place the
text at a certain location in the picture box. This example is rather
simple, but its purpose is to give you an idea on how to simulate a
text box in Visual Basic to be more flexible with a mix of the
different types of fonts available.
Additional reference words: 1.00