Como programar el boton imprimir en c# 2010

Cerrado
c - 7 mar 2012 a las 20:46
 vic - 24 mar 2012 a las 23:33
Hola,



como programar el boton imprimir en c# 2010

1 respuesta

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Printing;

namespace WindowsApplication4
{
public partial class Form1 : Form
{
private Button botonImprimir = new Button();
private PrintDocument printDocument1 = new PrintDocument();


public Form1()
{
botonImprimir.Text = "Imprimir Formulario";
botonImprimir.Click += new EventHandler(printButton_Click);
printDocument1.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
this.Controls.Add(botonImprimir);
}

void printButton_Click(object sender, EventArgs e)
{
CapturarPantalla();
printDocument1.Print();
}

Bitmap imagen;

private void CapturarPantalla()
{
Graphics g = this.CreateGraphics();
Size s = this.Size;
imagen = new Bitmap(s.Width, s.Height, g);
Graphics g2 = Graphics.FromImage(imagen);
g2.CopyFromScreen(this.Location.X, this.Location.Y, 0, 0, s);
}

private void printDocument1_PrintPage(System.Object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(imagen, 0, 0);
}

}
}
4