[Resolvido] Passar informação de um evento para o outro
Montei uma pagina para impressão mas não quero repetir o mesmo código no evento em que vai fazer a impressão.
Leia os comentários no código : }
using System;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;
namespace DrawString
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
foreach(var printter in PrinterSettings.InstalledPrinters)
{
comboBox1.Items.Add(printter);
}
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
//Quero passar o que esta formatado aqui para o outro evento sem precisar de reetir o codigo
Graphics g = panel1.CreateGraphics();
SolidBrush s = new SolidBrush(Color.Black);
FontFamily ff = new FontFamily("Arial");
Font font = new Font(ff, 50);
g.DrawString("TESTE", font, s, 10, 43);
}
private void BtnImprimir_Click(object sender, EventArgs e)
{
using (var pd = new PrintDocument())
{
pd.PrintPage += PanelPrintPage;
pd.PrinterSettings.PrinterName = comboBox1.SelectedItem.ToString();
pd.Print();
}
}
private void PanelPrintPage(object sender, PrintPageEventArgs e)
{
//E passar para aqui sem repetir o codigo acima onde vai fazer a impressao
}
}
}Discussão (2)
Carregando comentários...