Visual Basic.NET - Imprimir Juntificado en ambos lados

 
Vista:
sin imagen de perfil
Val: 4
Ha aumentado su posición en 15 puestos en Visual Basic.NET (en relación al último mes)
Gráfica de Visual Basic.NET

Imprimir Juntificado en ambos lados

Publicado por Adolfo (6 intervenciones) el 06/12/2018 23:40:00
Buenas noches amigos: Tengo una rutina de Justificar en ambos lados para imprimir, hecha en Visual Basic 6.0, al verme obligado a cambiar a Visual Basic 2010 o vb.Net, me encuentro que la rutina me da error en todos los códigos Printer.

Como no se como convertir los codigos de esta rutina a Visual Basic 2010 o vb.Net, para imprimir con e.Graphics.DrawString, por eso me pongo en contacto con vosotros, por si alguno tiene a bien darme alguna solución para poder modificar los códigos necesarios.

Se que hay muchas personas con mucho nivel en programacion y que seguramente me darán alguna solución, por lo que os doy las gracias anticipadas por robaros un poco de vuestro tiempo.

Saludos: Adolfo Lago



Esta es la rutina que os comente anteriormente

1
2
3
Option Explicit
Dim GuardoLine As Integer
Dim strPara As String ' Cadena que contiene el párrafo que se imprimirá


‘parametros que se envian para que justificar en ambos lados la escrutura

1
strPara = txtDescripcion.text                            ‘envia a strPara el contenido del textbox multilinea


1
PrintJustify strPara,1700,8295,200,200            ‘1700 desde  8295 hasta donde debe imprimir



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
Private Sub PrintJustify(ByVal strText As String, xLeft As Integer, xRight As Integer, yStart As Integer, Optional ySpacing As Integer)
 
    Dim aWords() As String    'Matriz que contiene todas las palabras strText
    Dim iWords As Integer     'El número de palabras que se imprimirá en la actual iLine
    Dim iWidth As Integer     ' El espacio disponible para una línea Para imprimir en
    Dim iLine As Integer       ' La línea actual Para imprimir
    Dim xSpace As Integer   'La cantidad de espacio entre cada palabra para imprimir
    Dim xPrint As Integer      'La posición x que la palabra siguiente se imprimirá en
    Dim yPrint As Integer     'La posición y que la palabra siguiente se imprimirá en
    Dim strWords As String       '  Una cadena que contiene las palabras de la línea que desea imprimir
    Dim i As Integer                 ‘Variable Para contador / Siguiente
    Dim j As Integer                ‘Variable Para  contador / Siguiente
        strText = Replace(strText, vbCrLf, " ")    'Reemplazar cualquier CRLF con el espacio
    strText = Replace(strText, " ", " ")   ‘Reemplaza “” con “”
        strText = Trim(strText)         ' Eliminar cualquier espacio antes o después   
      ‘                Inicializar Line Counter
    iLine = 0
                                      ' Establecer ySpacing predeterminado   
    If ySpacing = 0 Then
        ySpacing = 200
    End If
    '   'Calcular ancho de columna Imprimir
    iWidth = xRight - xLeft
            ' Seguir procesando hasta que todas las líneas sean impresas    
    Do Until strText = ""
        '                       'Incrementa Line Counter
        iLine = iLine + 1
        '                         'Calcular yPrint
        yPrint = yStart + ((iLine - 1) * ySpacing)
        '                           'Rompe strText en pedazos
        Erase aWords
 
        aWords = Split(strText, " ")
        '                                 'Determinar ¿Cuántas palabras caben en line
        strWords = ""
 
        For i = 0 To UBound(aWords)
 
                    If i = 0 Then
                        strWords = aWords(0)
                    Else
                        strWords = strWords & " " & aWords(i)
                    End If
 
                If Printer.TextWidth(strWords) > iWidth Then
 
                    iWords = i – 1     '                última palabra se convierte en la primera palabra de la línea siguiente
 
                    Exit For
                End If
        Next i
                         '                 'Vuelva a escribir strText Si todavía quedan palabras
        strText = ""
 
        If iWords < UBound(aWords) Then
 
                    For i = iWords + 1 To UBound(aWords)
 
                        If i = iWords + 1 Then
                            strText = aWords(i)
                        Else
                            strText = strText & " " & aWords(i)
                        End If
                    Next i
        Else                           '                'Imprime última línea sin justificación
 
            Printer.CurrentX = xLeft
            Printer.CurrentY = yPrint
            Printer.Print strWords
            Guarda = yPrint
 
            Exit Sub
        End If
        '                       "Ahora podemos imprimir Linea Justificada
 
‘Obtener el ancho de todas las palabras que se imprimirán, no los espacios
 
        strWords = ""
 
 
        For i = 0 To iWords
            strWords = strWords & aWords(i)
        Next i
        '                              Obtener el ancho del espacio en blanco
        xSpace = iWidth - Printer.TextWidth(strWords)
        '                        'Calcular el espacio en blanco entre las palabras
        If iWords <> 0 Then
        xSpace = Int(xSpace / iWords)
        End If
        '                                    'Imprime última palabra justificado a la derecha
        Printer.CurrentX = xRight - Printer.TextWidth(aWords(iWords))
        Printer.CurrentY = yPrint
        Printer.Print aWords(iWords)
'Palabras de impresión Xspace aparte
 
 
        For i = 0 To iWords - 1 'We just printed the last word    "Nos acaba de imprimir la última palabra
                                    'Calcular xPrint
            xPrint = xLeft
 
                For j = 1 To i
                    xPrint = xPrint + Printer.TextWidth(aWords(j - 1)) + xSpace
                Next j
                Printer.CurrentX = xPrint
                Printer.CurrentY = yPrint
                Printer.Print aWords(i)
 
        Next i
    Loop
 
End Sub
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder