19.04.2017 Views

Learn to Program with Small Basic

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

DrawText() takes three arguments. The first two arguments set the x- and<br />

y-coordinates of the upper-left corner of the text, and the third argument<br />

takes a string of the text (or numbers) you want <strong>to</strong> draw. Remember <strong>to</strong> put<br />

the string in quotes.<br />

If you want <strong>to</strong> change how the text appears, use the GraphicsWindow<br />

object properties in Table 3-1.<br />

Table 3-1: GraphicsWindow Properties for the Font Name, Size, Style, and Color<br />

Property Default Description<br />

FontName "Tahoma" The name of the font<br />

FontSize 12 The size of the font<br />

FontBold "True" Whether or not the font’s bold<br />

FontItalic "False" Whether or not the font’s italic<br />

BrushColor "SlateBlue" The color of the brush that draws the text<br />

If you don’t change any of these properties, <strong>Small</strong> <strong>Basic</strong> uses the default<br />

values listed in Table 3-1. The program in Listing 3-6 changes these properties<br />

<strong>to</strong> draw some fancy text.<br />

1 ' Fonts.sb<br />

2 GraphicsWindow.Title = "Fonts"<br />

3 GraphicsWindow.BackgroundColor = "LightYellow"<br />

4 GraphicsWindow.FontName = "Times New Roman"<br />

5 GraphicsWindow.FontSize = 120<br />

6 GraphicsWindow.FontItalic = "True"<br />

7<br />

8 GraphicsWindow.BrushColor = "Silver" ' Text shadow color<br />

9 GraphicsWindow.DrawText(5, 5, "Hello!") ' Shadow position/text<br />

10<br />

11 GraphicsWindow.BrushColor = "RosyBrown" ' Text color<br />

12 GraphicsWindow.DrawText(0, 0, "Hello!") ' Position and text<br />

Listing 3-6: Trying out some fonts<br />

In line 3, the BackgroundColor property changes the background color<br />

of the graphics window. Lines 4–6 set the name, size, and italics properties<br />

of the font you use in any calls <strong>to</strong> DrawText(). Line 8 sets the color of the font<br />

using the BrushColor property, and line 9 draws the string "Hello!" starting<br />

at point (5, 5). This line draws<br />

the background shadow you see<br />

in Figure 3-13. In line 11, the program<br />

changes the BrushColor property,<br />

and then line 12 draws the<br />

same string in a slightly different<br />

position. This creates the appearance<br />

of text <strong>with</strong> a background<br />

shadow, as shown in Figure 3-13.<br />

Figure 3-13: The output of Fonts.sb<br />

36 Chapter 3

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!