El Guru Programador
Usuario DESCONOCIDO | Registrate Gratis | Usuarios Registrados
Foro de Visual Basic/VB.NET
Foros del Guru > Visual Basic/VB.NET
Usuario Porfiii, como puedo Imprimir un SS...
Desconocido
Enviado - 29/11/2004
 
Tengo un formulario con un monton de SSpanel que a su vez contienen un monton de controles con datos e imagenes y me gustaría saber si existe alguna manera de enviar un control con todo su contenido a la impresora

Gracias
 
l_island
117 Mensaje(s)
Enviado - 30/11/2004
 
Encontré un fragmento de código en la ayuda de VB6 y después de modifcarlo resultó que tal vez te pueda servir de ayuda.
El resultado es parecido a un Form1.PrintForm.
Necesitas poner un PictureBox en tú formulario, aunque está invisible, después de la llamada a la función CopyPanel solo debes ejecutar un 'Pinter.PaintPicture Picture1'.

Option Explicit

Type RECT_Type
left As Long
top As Long
right As Long
bottom As Long
End Type
Declare Function GetActiveWindow Lib "User32" () As Long
Declare Function GetDesktopWindow Lib "User32" () As Long

Declare Function GetDC Lib "User32" (ByVal Hwnd As Long) As Long
Declare Function CreateCompatibleDC Lib "Gdi32" (ByVal hdc As Long) _
As Long
Declare Function CreateCompatibleBitmap Lib "Gdi32" (ByVal hdc _
As Long, ByVal nWidth As Long, _
ByVal nHeight As Long) As Long
Declare Function SelectObject Lib "Gdi32" (ByVal hdc As Long, _
ByVal hObject As Long) As Long
Declare Function BitBlt Lib "Gdi32" (ByVal hDestDC As Long, _
ByVal X As Long, ByVal Y _
As Long, ByVal nWidth As Long, _
ByVal nHeight As Long, _
ByVal hSrcDC As Long, _
ByVal XSrc As Long, _
ByVal YSrc As Long, _
ByVal dwRop As Long) As Long
Declare Function OpenClipboard Lib "User32" (ByVal Hwnd As Long) As Long
Declare Function EmptyClipboard Lib "User32" () As Long
Declare Function SetClipboardData Lib "User32" (ByVal wFormat As Long, _
ByVal hMem As Long) As Long
Declare Function CloseClipboard Lib "User32" () As Long
Declare Function ReleaseDC Lib "User32" (ByVal Hwnd As Long, _
ByVal hdc As Long) As Long
Declare Function DeleteDC Lib "Gdi32" (ByVal hdc As Long) As Long

Const SRCCOPY = &HCC0020
Const CF_BITMAP = 2

Function CopyPanel(miForm As Form, miPanel As SSPanel, miPicture As PictureBox)
Dim DeskHwnd As Long
Dim hdc As Long
Dim hdcMem As Long
Dim rect As RECT_Type
Dim junk As Long
Dim fwidth As Long, fheight As Long
Dim hBitmap As Long


'---------------------------------------------------
' Tomar el Handle de miForm
'---------------------------------------------------
DeskHwnd = miForm.Hwnd 'GetDesktopWindow()

'---------------------------------------------------
' Ancho alto del control a copiar
'---------------------------------------------------
fwidth = miPanel.Width / Screen.TwipsPerPixelX
fheight = miPanel.Height / Screen.TwipsPerPixelX

'---------------------------------------------------
' Hdc para el bitmap
'---------------------------------------------------
hdc = GetDC(DeskHwnd)
hdcMem = CreateCompatibleDC(hdc)
hBitmap = CreateCompatibleBitmap(hdc, fwidth, fheight)

If hBitmap <> 0 Then
junk = SelectObject(hdcMem, hBitmap)

'---------------------------------------------
' Copiar el bitMap a memoria
'---------------------------------------------
junk = BitBlt(hdcMem, 0, 0, fwidth, fheight, hdc, miPanel.left / Screen.TwipsPerPixelX, _
miPanel.top / Screen.TwipsPerPixelX, SRCCOPY)

'---------------------------------------------
' Copiar el bitmap al portapeles
'---------------------------------------------
junk = OpenClipboard(DeskHwnd)
junk = EmptyClipboard()
junk = SetClipboardData(CF_BITMAP, hBitmap)
junk = CloseClipboard()
End If

'---------------------------------------------
' Limpiar Handles
'---------------------------------------------
junk = DeleteDC(hdcMem)
junk = ReleaseDC(DeskHwnd, hdc)

'---------------------------------------------
' Copiar portapapeles en miPicture
'---------------------------------------------
miPicture.Picture = Clipboard.GetData()
End Function


Este código debes ponerlo en un módulo.

Saludos!!

l_island
 
 

 

Contactos myStudio Network