Created
March 22, 2018 02:42
-
-
Save Fhernd/fd5d11dd5ed141bdcc301f624e2bda51 to your computer and use it in GitHub Desktop.
Impresión de bloque de texto. OrtizOL.
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 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