Available in the LEADTOOLS Imaging toolkit. |
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.
Private Sub Lead1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim TestText As String
Dim TextWidth As Single
Dim TextHeight As Single
'Specify the text, font, and styles
TestText = "This is my text."
Lead1.Font.Name = "Times New Roman"
Lead1.Font.Size = 16
Lead1.DrawFontColor = RGB(0, 0, 255) 'Blue
Lead1.TextStyle = EFX_TEXTSTYLE_NORMAL
Lead1.TextAlign = EFX_TEXTALIGN_HCENTER_VCENTER
'Use the same scalemode as the mouse.
Lead1.ScaleMode = 1
'Get the width and height of the text to be drawn.
TextWidth = Lead1.DrawTextWidth(TestText)
TextHeight = Lead1.DrawTextHeight(TestText)
'set the location for the text
Lead1.TextTop = y
Lead1.TextLeft = x
Lead1.TextWidth = TextWidth
Lead1.TextHeight = TextHeight
'Set the properties for drawing a rectangle behind the text.
Lead1.DrawPenStyle = DRAWPENSTYLE_SOLID
Lead1.DrawMode = DRAWMODE_COPY_PEN
Lead1.DrawFillColor = RGB(0, 255, 0) 'Green
'Draw on the screen, not on the bitmap.
Lead1.DrawPersistence = False
'Draw the rectangle, then draw the text.
Lead1.DrawRectangle x, y, TextWidth, TextHeight
Lead1.DrawText TestText, 0
End Sub