Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DrawText

Status
Not open for further replies.

hansu

Programmer
Mar 12, 2002
89
I loop through a recordset to print it's contents. One field contains multipleline text. To print that field I use the API-function DrawText.
I need to set the rec.bottom property dynamically to get the right size of the RECT depending on the size of the text in the field.
So far I have not succeeded to ge a satisfying solution.

Can anyone advise? Thanks for your assistance.
 
Its hard to be sure about alternatives without knowing how your printing, nor to what you're printer to, but you may be able to look at the .TextHeight property, available to the Printer object, Form object, Picture Box, and a couple of others. In any event, that method will return the height of the text being printed, at the current font settings for that object, from which you might able to set the size of the RECT structure. There is also a corresponding .TextWidth property which may also be helpful. Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Thank you CajunCenturion
I use the following code. But TextHeight(rstOffPos("Beschreibung")) returns always the same value, whether the fiels contains one or more lines. Have you got an idea?

Code:
Private Sub OffPositionsPreview()
rstOffPos.MoveFirst
ob.CurrentY = 117
ob.FontBold = False
Dim rec2 As RECT
Dim strBeschr As String

Do While Not rstOffPos.EOF

        With rec2
            .Left = 35 * 3.78
            .Top = ob.CurrentY * 3.78
            .Right = 440
            .Bottom = .Top + TextHeight(rstOffPos("Beschreibung")) 
        End With
   
    strBeschr = Trim(rstOffPos("Beschreibung"))
    DrawText ob.hdc, strBeschr, Len(strBeschr), rec2, DT_LEFT + DT_WORDBREAK
    ob.CurrentX = 15: ob.Print rstOffPos("Position"),
    ob.CurrentX = 122: ob.Print rstOffPos("Menge"),
    If Not IsNull(rstOffPos("EinhID")) Then
        ob.CurrentX = 139: ob.Print rstOffPos("EinhID"),
    End If
    PrintLen = ob.TextWidth(rstOffPos("Einhpreis"))
    ob.CurrentX = 163 - PrintLen: ob.Print Format(rstOffPos("Einhpreis"), "###0.00"),
    PrintLen = ob.TextWidth(rstOffPos("Betrag"))
    ob.CurrentX = 185 - PrintLen: ob.Print Format(rstOffPos("Betrag"), "###0.00")
    ob.CurrentY = rec2.Bottom / 3.78
    rstOffPos.MoveNext
Loop
End Sub
 
I solved the problem.
Had to add
Code:
DrawText ob.hdc, strBeschr, Len(strBeschr), rec2, DT_LEFT + DT_WORDBREAK + DT_CALCRECT
after the first call of DrawText.
 
Perhaps it was a typo, and maybe it doesnt make any difference, but the following line

.Bottom = .Top + TextHeight(rstOffPos("Beschreibung"))

should read as

.Bottom = .Top + ob.TextHeight(rstOffPos("Beschreibung"))

In any event, glad you found a solution. Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
ob can either be a picturebox or the printer.object.
For a reason that I don't see at this moment
Code:
.Bottom = .Top + ob.TextHeight(rstOffPos("Beschreibung"))
prints just one line of text although the RECT is correctly set.
If I skip ob. it works fine.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top