' To
create a block text effect, draw the text twice, first offset in one
color, then with a second color.
Private Sub
BlockTextButton_Click(ByVal sender
As System.Object,
ByVal e As
System.EventArgs) Handles
BlockTextButton.Click
Dim textSize As SizeF
Dim g As Graphics
Dim theBackBrush As Brush =
Brushes.Black
Dim theForeBrush As Brush =
Brushes.Aquamarine
Dim theFont As
New Font("Times
New Roman", Me.FontSizeUpDown.Value,
FontStyle.Regular)
Dim xLocation, yLocation As
Single '
Used for the location
Dim i As
Integer
' Create a Graphics object from the picture box & clear it.
g =
DemoPictureBox.CreateGraphics()
g.Clear(Me.SampleBackColorPictureBox.BackColor)
' Measure the string that is to be drawn.
textSize = g.MeasureString(Me.TextSampleTextBox.Text,
theFont)
' Get the locations once to eliminate redundant calculations
xLocation = (DemoPictureBox.Width
- textSize.Width) / 2
yLocation = (DemoPictureBox.Height
- textSize.Height) / 2
' Draw the Black background first
' The text must be drawn repeatedly from the offset right to
' where the main text will be drawn.
For i = CInt(BlockDepthNumericUpDown.Value)
To 0 Step
-1
g.DrawString(TextSampleTextBox.Text, theFont, theBackBrush, _
xLocation - i,
yLocation + i)
Next
' Draw the second color main text over the first color.
g.DrawString(TextSampleTextBox.Text, theFont, theForeBrush, xLocation,
yLocation)
End
Sub