Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Drawing;
- using System.Drawing.Printing;
- using System.Windows.Forms;
- namespace R815ImprimirVariosDocumentos
- {
- public partial class Principal : Form
- {
- public Principal()
- {
- InitializeComponent();
- }
- private void btnImprimir_Click(object sender, EventArgs e)
- {
- string[] textoImpresion = new string[101];
- for (int i = 0; i < 101; i++)
- {
- textoImpresion[i] = i.ToString();
- textoImpresion[i] += ": Programad como un profesional.";
- }
- PrintDocument documento = new DocumentoTexto(textoImpresion);
- documento.PrintPage += documento_PrintPage;
- PrintDialog printDialog = new PrintDialog();
- printDialog.Document = documento;
- if (printDialog.ShowDialog() == DialogResult.OK)
- {
- documento.Print();
- }
- }
- private void documento_PrintPage(object sender, PrintPageEventArgs e)
- {
- DocumentoTexto doc = (DocumentoTexto) sender;
- using (Font fuente = new Font("Trebuchet", 10))
- {
- float altoLinea = fuente.GetHeight(e.Graphics);
- float x = e.MarginBounds.Left;
- float y = e.MarginBounds.Top;
- doc.NumeroPagina += 1;
- while ((y + altoLinea) < e.MarginBounds.Bottom && doc.Desplazamiento <= doc.Texto.GetUpperBound(0))
- {
- e.Graphics.DrawString(doc.Texto[doc.Desplazamiento], fuente, Brushes.Black, x, y);
- doc.Desplazamiento += 1;
- y += altoLinea;
- }
- if (doc.Desplazamiento < doc.Texto.GetUpperBound(0))
- {
- e.HasMorePages = true;
- }
- else
- {
- doc.Desplazamiento = 0;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement