Skip to content

Imprimir en varias líneas un texto

August 7, 2012
'Uso

Dim altoNecesario As Single = calcularAltoNecesario(strTexto, fntFuente, e, 
e.MarginBounds.Right - xPos)

e.Graphics.DrawString(strTexto, fntFuente, Brushes.Black, 
New RectangleF(xPos, yPos, e.MarginBounds.Right - xPos, altoNecesario))


'##################

'Función

Private Function calcularAltoNecesario(ByVal strTexto As String
ByVal fuente As Font, ByVal e As PrintPageEventArgs,  
ByVal espacioDisponible As Single) As Single
If e.Graphics.MeasureString(strTexto, fuente).Width > espacioDisponible 
        Then
'Varias lineas
Dim numLineas As Single
           e.Graphics.MeasureString(strTexto, fuente).Width / espacioDisponible

If (numLineas - CInt(numLineas)) > 0 Then
numLineas += 1
End If

Return e.Graphics.MeasureString(strTexto, fuente).Height * CInt(numLineas)
End If

'Una linea
Return e.Graphics.MeasureString(strTexto, fuente).Height
End Function

From → Impresión

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: