Un detalle: sería bueno hacer .Dispose() a los bitmaps una vez que terminaste 
de usarlos.

Un saludo.

 

  _____  

De: [email protected] [mailto:[EMAIL PROTECTED] En nombre de Eliseo Alegre
Enviado el: Lunes, 03 de Marzo de 2008 01:09 p.m.
Para: vbnet List Member
Asunto: [vbnet] Grabar o imprimir el contenido de un panel

 

Sos un maestro! Gracias por el ejemplo. Lo voy a probar, pero por lo que ví es 
exactamente lo que necesito.

 

GRACIAS!!!

 

Eliseo

        ----- Original Message ----- 

        From: Diego Cepero <mailto:[EMAIL PROTECTED]>  

        To: vbnet List Member <mailto:[email protected]>  

        Sent: Monday, March 03, 2008 2:34 PM

        Subject: [vbnet] Grabar o imprimir el contenido de un panel

         

        Hola, 

         

                    Hacé un proyecto con un formulario, que tenga un panel. 
Agregá varios controles a ese panel, y pegá el siguiente código en el 
formulario:

         

        Imports System.Windows.Forms

        Imports System.Drawing

        Imports System.Drawing.Imaging

        Imports System.Drawing.Printing

         

        Public Class Form1

         

           Private Sub btnGenerarJpg_Click(ByVal sender As System.Object, ByVal 
e As System.EventArgs) Handles btnGenerarJpg.Click

              GuardarPanelComoJpg(Me.Panel1, "c:\temp\panel1.jpg")

           End Sub

         

           Private Sub btnImprimir_Click(ByVal sender As System.Object, ByVal e 
As System.EventArgs) Handles btnImprimir.Click

              ImprimirPanel(Me.Panel1)

           End Sub

         

           Private Sub GuardarPanelComoJpg(ByVal panel As Panel, _

                                           ByVal ruta As String)

         

              Dim rect As Rectangle = panel.ClientRectangle

              Dim jpg As New Bitmap(rect.Width, rect.Height)

         

              panel.DrawToBitmap(jpg, rect)

         

              jpg.Save(ruta, ImageFormat.Jpeg)

           End Sub

         

           Private Sub ImprimirPanel(ByVal panel As Panel)

         

              Dim pd As New ImpresorPanel(panel)

              Dim pvw As New PrintPreviewDialog()

         

              pvw.Document = pd

              pvw.ShowDialog()

           End Sub

        End Class

         

        Public Class ImpresorPanel

           Inherits PrintDocument

         

           Private _panel As Panel

         

           Public Sub New(ByVal panel As Panel)

              _panel = panel

           End Sub

         

           Public ReadOnly Property Panel() As Panel

              Get

                 Return _panel

              End Get

           End Property

         

           Protected Overrides Sub OnPrintPage(ByVal e As 
System.Drawing.Printing.PrintPageEventArgs)

              MyBase.OnPrintPage(e)

         

              Dim rect As Rectangle = Me.Panel.ClientRectangle

              Dim bmp As New Bitmap(rect.Width, rect.Height)

         

              Me.Panel.DrawToBitmap(bmp, rect)

              e.Graphics.DrawImage(bmp, 0, 0)

           End Sub

        End Class

         

                    Si querés imprimir en lugar de hacer una vista previa, 
llamá a pd.Print() en lugar de pvw.ShowDialog().

                    Un saludo.

         

        
  _____  


        De: [email protected] [mailto:[EMAIL PROTECTED] En nombre de Eliseo 
Alegre
        Enviado el: Lunes, 03 de Marzo de 2008 10:59 a.m.
        Para: vbnet List Member
        Asunto: [vbnet] Grabar o imprimir el contenido de un panel

         

        Lista:

         

        alguien sabe como puedo grabar una imagen (jpg) de todo el contenido de 
un panel? o como puedo hacer para que ese contenido se imprima?

         

        Gracias

         

        Eliseo

Responder a