|
-
Jan 13th, 2003, 11:01 AM
#1
Thread Starter
Hyperactive Member
How to align the character to a common baseline??(How to find CurrentY)
Hello every1,
My problem looks like a simple one. But it has been bugging me for a while now. Actually I just want to print a name on a form using the "Print" statement. Sounds ez. But the thing is I wanna print each character in a different fontsize. Example: If I wanna print "VISUAL", I want V in 14 size, I in 16, S in 18 and so on. The problem is when i print the characters, there r not aligning to the same baseline. Thatz understandable coz with the increase in fontsize, the charcater may tend to grow and the size may increase. I deviced a logic which is
PS:ScaleMode is Pixel
Dim H1 as single,H2 as single
Me.FontSize=16
Me.CurrentX=10
Me.CurrentY=70
Me.Print "V"
H1=Me.TexhHeight("V")
Me.FontSize=16
H2=Me.TexhHeight("V")
Me.CurrentX=10
Me.CurrentY=70-(H2-H1)
Me.Print "V"
This logic is actually the correct one to find the CurrentY position but for some mysterious reason, It doesnt align. Kindly check my problem and provide a solution as early as possible.. Thanq
If Not VB Then Exit
------------------------------------------------
visit me @ http://mzubair.50g.com/
-
Jan 13th, 2003, 06:24 PM
#2
Frenzied Member
CurrentY is not what you think it is. Fonts do not map to space the way you want exactly - the DrawText api gets around this by letting you justify each character as you print it.
The DrawText api:
Code:
Const DC_ACTIVE = &H1
Const DC_NOTACTIVE = &H2
Const DC_ICON = &H4
Const DC_TEXT = &H8
Const BDR_SUNKENOUTER = &H2
Const BDR_RAISEDINNER = &H4
Const EDGE_ETCHED = (BDR_SUNKENOUTER Or BDR_RAISEDINNER)
Const BF_BOTTOM = &H8
Const BF_LEFT = &H1
Const BF_RIGHT = &H4
Const BF_TOP = &H2
Const BF_RECT = (BF_LEFT Or BF_TOP Or BF_RIGHT Or BF_BOTTOM)
Const DFC_BUTTON = 4
Const DFC_POPUPMENU = 5 'Only Win98/2000 !!
Const DFCS_BUTTON3STATE = &H10
Const DT_CENTER = &H1
Const DC_GRADIENT = &H20 'Only Win98/2000 !!
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function DrawCaption Lib "user32" (ByVal hWnd As Long, ByVal hdc As Long, pcRect As RECT, ByVal un As Long) As Long
Private Declare Function DrawEdge Lib "user32" (ByVal hdc As Long, qrc As RECT, ByVal edge As Long, ByVal grfFlags As Long) As Long
Private Declare Function DrawFocusRect Lib "user32" (ByVal hdc As Long, lpRect As RECT) As Long
Private Declare Function DrawFrameControl Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal un1 As Long, ByVal un2 As Long) As Long
Private Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long
Private Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function OffsetRect Lib "user32" (lpRect As RECT, ByVal x As Long, ByVal y As Long) As Long
Private Sub Form_Paint()
'KPD-Team 1999
'URL: http://www.allapi.net/
'E-Mail: [email protected]
Dim R As RECT
'Clear the form
Me.Cls
'API uses pixels
Me.ScaleMode = vbPixels
'Set the rectangle's values
SetRect R, 0, 0, Me.ScaleWidth, 20
'Draw a caption on the form
DrawCaption Me.hWnd, Me.hdc, R, DC_ACTIVE Or DC_ICON Or DC_TEXT Or DC_GRADIENT
'Move the recatangle
OffsetRect R, 0, 22
'Draw an edge on our window
DrawEdge Me.hdc, R, EDGE_ETCHED, BF_RECT
OffsetRect R, 0, 22
'Draw a focus rectangle on our window
DrawFocusRect Me.hdc, R
OffsetRect R, 0, 22
'Draw a frame control on our window
DrawFrameControl Me.hdc, R, DFC_BUTTON, DFCS_BUTTON3STATE
OffsetRect R, 0, 22
'draw some text on our form
DrawText Me.hdc, "Hello World !", Len("Hello World !"), R, DT_CENTER
End Sub
-
Jan 18th, 2003, 10:20 AM
#3
Thread Starter
Hyperactive Member
Thanx Jim
If Not VB Then Exit
------------------------------------------------
visit me @ http://mzubair.50g.com/
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|