Código C:
Ver original
private void btnDefinir_Click(object sender, EventArgs e) { try { PaperSize plantilla; plantilla = new PaperSize(lblVale.Text, Convert.ToInt32(txtAncho.Text), Convert.ToInt32(txtAlto.Text)); printDocument1.PrinterSettings = impresoraActual; printDocument1.DefaultPageSettings.PaperSize = plantilla; } catch (Exception ex) { MessageBox.Show(ex.Message, ex.Source); } }
Donde impresoraActual es :
Código C:
Ver original
PrinterSettings impresoraActual = new PrinterSettings();
Luego en el codigo del PrintDocument_PrintPage donde se dibuja la estructura a mostrar :
Código C:
Ver original
private void printDocument1_PrintPage(object sender, PrintPageEventArgs e) { try { Font fuente = new Font("Verdana", 8); //La unidad de medida a usar sera milimetros e.Graphics.PageUnit = GraphicsUnit.Millimeter; //1ra linea e.Graphics.DrawString(cliente_p[contador].ToString(), fuente, Brushes.Black, 30, 42); e.Graphics.DrawString(fecha_d[contador].ToString(), fuente, Brushes.Black, 107, 42); e.Graphics.DrawString(vale_d[contador].ToString(), fuente, Brushes.Black, 180, 42); //2da linea e.Graphics.DrawString(vale_p[contador].ToString(), fuente, Brushes.Black, 30, 46); e.Graphics.DrawString(cliente_d[contador].ToString(), fuente, Brushes.Black, 107, 46); e.Graphics.DrawString(factura_d[contador].ToString(), fuente, Brushes.Black, 180, 46); //3ra linea e.Graphics.DrawString(fecha_p[contador].ToString(), fuente, Brushes.Black, 30, 50); e.Graphics.DrawString(kilometraje_d[contador].ToString(), fuente, Brushes.Black, 107, 50); e.Graphics.DrawString(combustible_d[contador].ToString(), fuente, Brushes.Black, 180, 50); //4ta linea e.Graphics.DrawString(entrega_p[contador].ToString(), fuente, Brushes.Black, 30, 54); e.Graphics.DrawString(placa_d[contador].ToString(), fuente, Brushes.Black, 107, 54); e.Graphics.DrawString(importe_d[contador].ToString(), fuente, Brushes.Black, 180, 54); //5ta linea e.Graphics.DrawString(galones_p[contador].ToString(), fuente, Brushes.Black, 30, 58); e.Graphics.DrawString(chofer_d[contador].ToString(), fuente, Brushes.Black, 107, 58); e.Graphics.DrawString(galones_d[contador].ToString(), fuente, Brushes.Black, 180, 58); //6ta linea e.Graphics.DrawString(importe_p[contador].ToString(), fuente, Brushes.Black, 30, 62); if (contador < paginas - 1) { contador = contador + 1; e.HasMorePages = true; } else { e.HasMorePages = false; } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.Source); } }
Verán que indico la unidad a medida a usar la defino a milimetros, pero al momento de mostrar no figura la imagen porque no muestra nada porque si yo defino el alto y el ancho de la hoja en milimetros en las cajas de texto 225 y 102 no muestra, pero si defino una cantidad mas alta como 900 x 370 cuadra en la imagen pero al imprimir no cuadra con lo impreso en las coordenadas en milimetros que definí. Espero vuestra ayuda. Saludos!

PDT: No importa si las respuestas que me puedan brindar son en VB.NET igual sé su definicion en c#