Visual Basic - Rutina IMPRIMIR

Life is soft - evento anual de software empresarial
 
Vista:

Rutina IMPRIMIR

Publicado por Hector Morales (23 intervenciones) el 29/01/2007 18:39:13
HOLA A TODOS ESPERO QUE ME PUEDAN AYUDAR

LO UNICO QUE NECESITO ES SABER COMO HAGO UNA RUTINA PARA IMPRIMIR EL FORMULARIO Y QUE ME SALGA COMO UNA HOJA DE WORD, PERO LO QUE NECESITO MAS URGENTE ES QUE SALGA IMPRESO HORIZONTALMENTE.

GRACIAS Y OJALA ME PUEDAN AYUDAR

HASTA LUEGO
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

RE:Rutina IMPRIMIR

Publicado por maree (30 intervenciones) el 29/01/2007 21:27:46
Hola, te paso un codigo. Esta el sub que va a manejar la impresion. Para esto debes crear el formulario (labels, textbox, etc; o sea todo lo q quieres q se imprima), dentro de un picturebox, q puedes hacer invisible en pantalla pero te va a servir para poder imprimirlo. Esto en caso de q lo q quieras sea imprimir todo los controles como aparecen en pantalla. Si solo quieres imprimir el texto la cosa cambia, y mucho mas facil, solo usas un textbox q te sirva como una textarea mas o menos :-).


'Declaracion de variables necesarias para el sub de impresion

Private Declare Function SendMessage Lib "user32.dll" Alias _
"SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long

Private Const WM_PAINT = &HF
Private Const WM_PRINT = &H317
Private Const PRF_CLIENT = &H4& ' Draw the window's client area
Private Const PRF_CHILDREN = &H10& ' Draw all visible child
Private Const PRF_OWNED = &H20& ' Draw all

...
...
...
...

Public Sub PrintPictureBox(Box As PictureBox, _
Optional X As Single = 0, _
Optional Y As Single = 0)
Dim rv As Long
Dim ar As Boolean

On Error GoTo Exit_Sub

With Box
'Save ReDraw value
ar = .AutoRedraw

'Set persistance
.AutoRedraw = True

'Wake up printer
Printer.Print

'Draw controls to picture box
rv = SendMessage(.hwnd, WM_PAINT, .hDC, 0)
rv = SendMessage(.hwnd, WM_PRINT, .hDC, _
PRF_CHILDREN + PRF_CLIENT + PRF_OWNED + PRF_PRUEBA)

'Refresh image to picture property
.Picture = .Image

'Copy picture to Printer
Printer.PaintPicture .Picture, X, Y

'Restore backcolor (Re-load picture if picture was used)
'Box.Line (0, 0)-(.ScaleWidth, .ScaleHeight), .BackColor, BF

'Restore ReDraw
'.AutoRedraw = ar
End With

Exit_Sub:
If Err.Number Then MsgBox Err.Description, vbOKOnly, "Printer Error!"

End Sub

..
..
..

'Funcion de boton q tira la impresion

Private Sub Command6_Click()

'haces el botn invisible, para q no salga en la impresion
Command6.Visible = False

'esta linea te permite imprimir horizontalmente
Printer.Orientation = vbPRORLandscape

'Esta es la llamada al sub PrintPictureBox(picturebox q vas a imprimir, X, Y)
PrintPictureBox Picture8, 2000, 2000

'cierra la impresion
Printer.EndDoc

'vuelve a aparecer el boton para nuevas impresiones
Command6.Visible = True

'******************************************************
End Sub

ESPERO Q TE SIRVA, BYE..
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar