Advertisement
Fhernd

Principal.cs

Mar 20th, 2018
1,424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.32 KB | None | 0 0
  1. using System;
  2. using System.Drawing;
  3. using System.Drawing.Printing;
  4. using System.Windows.Forms;
  5.  
  6. namespace R814ImprimirDocumento
  7. {
  8.     public partial class Principal : Form
  9.     {
  10.         public Principal()
  11.         {
  12.             InitializeComponent();
  13.         }
  14.  
  15.         private void btnImprimirDocumento_Click(object sender, EventArgs e)
  16.         {
  17.             PrintDocument documento = new PrintDocument();
  18.             documento.PrintPage += this.Documento_PringPage;
  19.  
  20.             PrintDialog dialogoImpresion = new PrintDialog();
  21.             dialogoImpresion.Document = documento;
  22.  
  23.             if (dialogoImpresion.ShowDialog() == DialogResult.OK)
  24.             {
  25.                 documento.Print();
  26.             }
  27.         }
  28.  
  29.         private void Documento_PringPage(object sender, PrintPageEventArgs e)
  30.         {
  31.             using (Font fuente = new Font("Trebuchet", 30))
  32.             {
  33.                 float x = e.MarginBounds.Left;
  34.                 float y = e.MarginBounds.Top;
  35.  
  36.                 float altoLinea = fuente.GetHeight(e.Graphics);
  37.  
  38.                 for (int i = 0; i < 5; i++)
  39.                 {
  40.                     e.Graphics.DrawString("Línea de texto no. " + i.ToString(), fuente, Brushes.Black, x, y);
  41.  
  42.                     y += altoLinea;
  43.                 }
  44.             }
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement