Otro de los grandes retos que nos enfrentamos en el proyecto era al momento de implementar el botón de impresión de los datos de los estudiantes. Como este tema no fue visto propiamente en clases fue muy importante la consulta de tutoriales de C#, ejemplos de como se imprime utilizando el código adecuado. A continuación se expone la resolucuión con código implementado a través de la ayuda de internet. Este foro fue de mucha ayuda.
Link: http://social.msdn.microsoft.com/Forums/es/repdeves/thread/80ef3234-7ec1-4abb-96fe-514bd5a26de1
Link: http://social.msdn.microsoft.com/Forums/es/repdeves/thread/80ef3234-7ec1-4abb-96fe-514bd5a26de1
CÓDIGO IMPLEMENTADO EN NUESTRO PROYECTO
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern long BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
private Bitmap memImag;
private void CaptureScreen()
{
Graphics mygraph = this.CreateGraphics();
Size s = this.Size;
memImag = new Bitmap(s.Width, s.Height, mygraph);
Graphics memGraph = Graphics.FromImage(memImag);
IntPtr dc1 = mygraph.GetHdc();
IntPtr dc2 = memGraph.GetHdc();
BitBlt(dc2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 0, 0, 13369376);
mygraph.ReleaseHdc(dc1);
memGraph.ReleaseHdc(dc2);
}
private void printDocument1_PrintPage(System.Object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(memImag, 0, 0);
}
private void btnImprimir_Click(object sender, EventArgs e)
{
CaptureScreen();
printDocument1.Print();
}
No hay comentarios:
Publicar un comentario