StringFormat Class

M

MikeG0930

I have a report that get's it's data from a form. One of the fields in the
report is for hobbies that I want to limit to the size of the region of a
rectangle. To do this, I am using this code:
Call DrawStringInBox(ev, 50, msngYPos, _
50, msngYPos + msngFontHeight, _
txtHobbies.Text)

Private Sub DrawStringInBox( _
ByVal ev As System.Drawing.Printing.PrintPageEventArgs, _
ByVal x1 As Single, ByVal y1 As Single, _
ByVal x2 As Single, ByVal y2 As Single, _
ByVal s As String)

Dim sfCurrent As New StringFormat()
Dim recCurrent As New RectangleF(x1, y1, x2, y2)
sfCurrent.Trimming = StringTrimming.Character
sfCurrent.Alignment = StringAlignment.Near
ev.Graphics.DrawString(s, mfntPrint, _
Brushes.Black, recCurrent, sfCurrent)
End Sub

The problem is instead of truncating the text to the nearest character, it
wordwraps to a new line.

Thanks for any help.
 
M

Mansi Shah

Hi,
From my knowledge i can say that DrawString will always draw the whole
string you have passed. If you want to crop it then you need to do that
before draw.

Regards,
Mansi Shah
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top