1
I need to print labels and I’m using the PrintDocument
, only there’s a problem I don’t know how I create the page for printing.
Ex. My label has 4 cm tall and 10 cm wide with margins of 0.2 cm. How can I set these
private void btnImprimir_Click(object sender, EventArgs e)
{
for (int i = 0; i < iQuantidadeVolumes; i++)
{
var volumeUnico = (i + 1).ToString();
for (int ii = 0; ii < ListaConteudoImpressao.Count; ii++)
{
if (ListaConteudoImpressao[ii].Contains("VOLUME : "))
{
ListaConteudoImpressao[ii] = sTextoNF + "VOLUME : " + volumeUnico + "/" + iQuantidadeVolumes.ToString();
Documento.PrinterSettings.PrinterName = sNomeImpressora;
Documento.DefaultPageSettings.Landscape = true;
Documento.Print();
}
}
}
}
private void Documeto_PrintPage(object sender, PrintPageEventArgs e)
{
string texto = "";
Font letra = new Font("Aerial", 23, FontStyle.Bold, GraphicsUnit.Pixel);
SolidBrush cor = new SolidBrush(Color.Black);
Rectangle retangulo = new Rectangle(0, 100, largura, 30);
StringFormat alinhamento = new StringFormat();
alinhamento.Alignment = StringAlignment.Center;
alinhamento.LineAlignment = StringAlignment.Center;
e.Graphics.DrawString(texto.ToUpper(), letra, cor, retangulo, alinhamento);
int y = 170;
foreach (string frase in ListaConteudoImpressao)
{
e.Graphics.DrawString(frase, letra, cor, new Point(20, y));
y += 40;
}
}
}
}