Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleDraw text centered at a position
DescriptionThis example shows how to draw text centered at a position in Visual Basic 6.
Keywordstext, center text, font
CategoriesGraphics, Strings
 
The CenterTextAt subroutine uses the TextWidth and TextHeight methods to see how big the text will be. It then adjusts the drawing position accordingly to center the text and use Print to display it.
 
Private Sub CenterTextAt(ByVal txt As String, ByVal x As _
    Single, ByVal y As Single)
Dim hgt As Single
Dim wid As Single

    ' Mark the center for debugging.
    Me.Line (x - 120, y)-Step(240, 0), vbRed
    Me.Line (x, y - 120)-Step(0, 240), vbRed

    hgt = Me.TextHeight(txt)
    wid = Me.TextWidth(txt)
    Me.CurrentX = x - wid / 2
    Me.CurrentY = y - hgt / 2
    Me.Print txt;
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated