Font example for Visual Basic
Note: Also works with Access 95 and 97.
This example, in a MouseUp event, determines the size of a rectangle for a string in the specified font. It then draws the rectangle and draws the text on top of the rectangle.
Dim TestText As String
Dim TextWidth As Single
Dim TextHeight As Single
Dim RasterFxd As New LEADRasterFXD
Dim hDC As Long
hDC = LEADRasterView1.GetClientDC()
'Specify the text, font, and styles
TestText = "This is my text."
RasterFxd.Font.Name = "Times New Roman"
RasterFxd.Font.Size = 16
RasterFxd.DrawFontColor = RGB(0, 0, 255) 'Blue
RasterFxd.TextStyle = FXD_TEXTSTYLE_NORMAL
RasterFxd.TextAlign = FXD_TEXTALIGN_HCENTER_VCENTER
'Get the width and height of the text to be drawn.
TextWidth = RasterFxd.DrawTextWidth(hDC, TestText)
TextHeight = RasterFxd.DrawTextHeight(hDC, TestText)
'set the location for the text
RasterFxd.TextTop = y
RasterFxd.TextLeft = x
RasterFxd.TextWidth = TextWidth
RasterFxd.TextHeight = TextHeight
'Set the properties for drawing a rectangle behind the text.
RasterFxd.DrawPenStyle = DRAWPENSTYLE_SOLID
RasterFxd.DrawMode = DRAWMODE_COPY_PEN
RasterFxd.DrawFillColor = RGB(0, 255, 0) 'Green
'Draw on the screen, not on the bitmap.
RasterFxd.DrawPersistence = False
'Draw the rectangle, then draw the text.
RasterFxd.DrawRectangle Nothing, hDC, x, y, TextWidth, TextHeight
RasterFxd.DrawText Nothing, hDC, TestText, 0
LEADRasterView1.ReleaseClientDC