Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created March 21, 2018 01:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/cc026ab519224d0cf20960b99d1da640 to your computer and use it in GitHub Desktop.
Save Fhernd/cc026ab519224d0cf20960b99d1da640 to your computer and use it in GitHub Desktop.
OrtizOL. Impresión de texto. C#.
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