Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created March 22, 2018 02:42
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/fd5d11dd5ed141bdcc301f624e2bda51 to your computer and use it in GitHub Desktop.
Save Fhernd/fd5d11dd5ed141bdcc301f624e2bda51 to your computer and use it in GitHub Desktop.
Impresión de bloque de texto. OrtizOL.
using System;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;
namespace R816ImprimirBloqueTexto
{
public partial class Principal : Form
{
public Principal()
{
InitializeComponent();
}
private void btnImprimir_Click(object sender, EventArgs e)
{
string texto = "La programación reactiva produce aplicaciones más robustas, eficientes y más amigables: " +
"Arquitectura orientada a evento, Resistencia a fallos, Garantía de respuesta, Escalabilidad.";
PrintDocument documento = new DocumentoParrafo(texto);
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)
{
DocumentoParrafo documento = (DocumentoParrafo) sender;
using (Font fuente = new Font("Trebuchet", 15))
{
e.Graphics.DrawString(documento.Texto, fuente, Brushes.Black, e.MarginBounds, StringFormat.GenericDefault);
}
}
}
public class DocumentoParrafo : PrintDocument
{
private string texto;
public string Texto { get; set; }
public DocumentoParrafo(string texto)
{
this.Texto = texto;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment