El sitio más completo sobre programación, recursos web y herramientas online para Webmasters
Fecha: 25/11/2005

Imprimir texto justificado

Trucos visual-basic:
Función para imprimir texto justificado en impresora.


Código Visual Basic


Función para imprimir texto justificado en impresora.
Sub justifica_printer(x0, xf, y0, txt)
' x0, xf = posicion de los margenes izquierdo y derecho
' y0 = posicion vertical donde se desea empezar a escribir
' txt = texto a escribir
Dim x, y, k, ancho
Dim s As String, ss As String
Dim x_spc
s = txt
x = x0
y = y0
ancho = (xf - x0)
While s <> ""
ss = ""
While (s <> "") And (Printer.TextWidth(ss) <= ancho)
ss = ss & Left$(s, 1)
s = Right$(s, Len(s) - 1)
Wend
If (Printer.TextWidth(ss) > ancho) Then
s = Right$(ss, 1) & s
ss = Left$(ss, Len(ss) - 1)
End If
' aqui tenemos en ss lo maximo que cabe en una linea
If Right$(ss, 1) = " " Then
ss = Left$(ss, Len(ss) - 1)
Else
If (InStr(ss, " ") > 0) And (Left$(s & " ", 1) <> " ") Then
While Right$(ss, 1) <> " "
s = Right$(ss, 1) & s
ss = Left$(ss, Len(ss) - 1)
Wend
ss = Left$(ss, Len(ss) - 1)
End If
End If
x_spc = 0
x = x0
If (Len(ss) > 1) And (s & "" <> "") Then
x_spc = (ancho - Printer.TextWidth(ss)) / (Len(ss) - 1)
End If
Printer.CurrentX = x
Printer.CurrentY = y
If x_spc = 0 Then
Printer.Print ss;
Else
For k = 1 To Len(ss)
Printer.CurrentX = x
Printer.Print Mid$(ss, k, 1);
x = x + Printer.TextWidth("*" & Mid$(ss, k, 1) & "*") - Printer.TextWidth("**")
x = x + x_spc
Next
End If
y = y + Printer.TextHeight(ss)
While Left$(s, 1) = " "
s = Right$(s, Len(s) - 1)
Wend
Wend
End SubFunción para imprimir texto justificado en un PictureBox.
Sub justifica_picture(p As PictureBox, x0, xf, y0, txt)
' Muestra un texto justificado dentro del picture "p"
' x0, xf = posicion de los margenes izquierdo y derecho
' y0 = posicion vertical donde se desea empezar a escribir
' txt = texto a escribir
Dim x, y, k, ancho
Dim s As String, ss As String
Dim x_spc
s = txt
x = x0
y = y0
ancho = (xf - x0)
While s <> ""
ss = ""
While (s <> "") And (p.TextWidth(ss) <= ancho)
ss = ss & Left$(s, 1)
s = Right$(s, Len(s) - 1)
Wend
If (p.TextWidth(ss) > ancho) Then
s = Right$(ss, 1) & s
ss = Left$(ss, Len(ss) - 1)
End If
' aqui tenemos en ss lo maximo que cabe en una linea
If Right$(ss, 1) = " " Then
ss = Left$(ss, Len(ss) - 1)
Else
If (InStr(ss, " ") > 0) And (Left$(s & " ", 1) <> " ") Then
While Right$(ss, 1) <> " "
s = Right$(ss, 1) & s
ss = Left$(ss, Len(ss) - 1)
Wend
ss = Left$(ss, Len(ss) - 1)
End If
End If
x_spc = 0
x = x0
If (Len(ss) > 1) And (s & "" <> "") Then
x_spc = (ancho - p.TextWidth(ss)) / (Len(ss) - 1)
End If
p.CurrentX = x
p.CurrentY = y
If x_spc = 0 Then
p.Print ss;
Else
For k = 1 To Len(ss)
p.CurrentX = x
p.Print Mid$(ss, k, 1);
x = x + p.TextWidth("*" & Mid$(ss, k, 1) & "*") - p.TextWidth("**")
x = x + x_spc
Next
End If
y = y + p.TextHeight(ss)
While Left$(s, 1) = " "
s = Right$(s, Len(s) - 1)
Wend
Wend
End Sub

Autor: Daniel Castillo Martinez
Imprimir texto justificado Categoría: Trucos, Visual Basic


Scripts Similares:

» Como obtener el nombre del equipo en visual basic
» Hacer parpadear el caption de una ventana
» Obtener y modificar la configuración regional
» Abrir componentes del Panel de Control Rundll32
» Abrir el explorador de windows
» Abrir el navegador por defecto en una URL determinada
» Abrir la aplicación asociada a un documento
» Abrir la ventana de Buscar archivos
» Abrir una base de datos con seguridad en ADO
» Abrir y cerrar la puerta del CD

Privacidad ּ Publicidad ּ Prensa ּ Premios ּ Colaborar ּ Enlazarnos ּ Mapa del Sitio ּ Aviso legal ּ Boletín ּ Contacto
2001 - 2011 | Sitio creado y mantenido por Gabriel Marcelo Rodríguez
Hosting de alta calidad a bajo costo Neolo.com.ar