Created
March 21, 2018 01:36
-
-
Save Fhernd/cc026ab519224d0cf20960b99d1da640 to your computer and use it in GitHub Desktop.
OrtizOL. Impresión de texto. C#.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Drawing; | |
using System.Drawing.Printing; | |
using System.Windows.Forms; | |
namespace R814ImprimirDocumento | |
{ | |
public partial class Principal : Form | |
{ | |
public Principal() | |
{ | |
InitializeComponent(); | |
} | |
private void btnImprimirDocumento_Click(object sender, EventArgs e) | |
{ | |
PrintDocument documento = new PrintDocument(); | |
documento.PrintPage += this.Documento_PringPage; | |
PrintDialog dialogoImpresion = new PrintDialog(); | |
dialogoImpresion.Document = documento; | |
if (dialogoImpresion.ShowDialog() == DialogResult.OK) | |
{ | |
documento.Print(); | |
} | |
} | |
private void Documento_PringPage(object sender, PrintPageEventArgs e) | |
{ | |
using (Font fuente = new Font("Trebuchet", 30)) | |
{ | |
float x = e.MarginBounds.Left; | |
float y = e.MarginBounds.Top; | |
float altoLinea = fuente.GetHeight(e.Graphics); | |
for (int i = 0; i < 5; i++) | |
{ | |
e.Graphics.DrawString("Línea de texto no. " + i.ToString(), fuente, Brushes.Black, x, y); | |
y += altoLinea; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment