Tema: imprimir c#
Ver Mensaje Individual
  #5 (permalink)  
Antiguo 01/07/2008, 07:23
pablokes
 
Fecha de Ingreso: enero-2008
Mensajes: 233
Antigüedad: 16 años, 3 meses
Puntos: 2
Respuesta: imprimir c#

private void Imprimir_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
int topMargin = Imprimir.DefaultPageSettings.Margins.Top;
int leftMargin = Imprimir.DefaultPageSettings.Margins.Left;
float linesPerPage = 0;
float verticalPosition = 0;
float horizontalPosition = leftMargin;
string textLine = null;
int currentLine = 0;
linesPerPage = 66;

while (currentLine < linesPerPage)
{
textLine = "nose q poner dame un ejemplo ;*/";
if (textLine == null)
{
break;
}
fuente = new Font("Courier", 9, FontStyle.Regular);
verticalPosition = topMargin + currentLine * fuente.GetHeight(e.Graphics);
#region formato de la hoja

PaperSize carta = new PaperSize();
carta.RawKind = 1;
Imprimir.DefaultPageSettings.PaperSize = carta;
//MessageBox.Show(Imprimir.DefaultPageSettings.Paper Size.ToString());
Dominio.Cliente client = new Dominio.Cliente();
client.Telefono1 = this.txtTelefono.Text;
ArrayList resultados = registro.buscarClienteTelefonoPrueba();

Pen myPen = new Pen(Color.Black);
myPen.DashStyle = DashStyle.Dash;
// e.Graphics.DrawRectangle(myPen,10, 20, 790, 100);
e.Graphics.DrawString("INFORME CLIENTES POR VENDEDORES " + DateTime.Now.ToShortDateString() + " Pagina: ", fuente, Brushes.Black, 130, 30, new StringFormat());
e.Graphics.DrawString("DE FECHA: " + DateTime.Now.ToShortDateString() + "A FECHA: " + DateTime.Now.ToShortDateString() + "DEL VENDEDOR: 4", fuente, Brushes.Black, 130, 50, new StringFormat());
int contador1Linea = 150;
int contador2Linea = 165;
int contador3Linea = 180;
int contador4Linea = 195;
int contador5Linea = 210;
int contador6Linea = 225;
int contador7Linea = 240;
int contador8Linea = 255;
#endregion
foreach (Dominio.Cliente cliente in resultados)
{

e.Graphics.DrawString("Nº REPORTE: " + Convert.ToString(cliente.NumeroReporte).Trim(), fuente, Brushes.Black, 0, contador1Linea, new StringFormat());
e.Graphics.DrawString("CODIGO CLIENTE: " + Convert.ToString(cliente.NumeroReporte).Trim(), fuente, Brushes.Black, 300, contador1Linea, new StringFormat());
e.Graphics.DrawString("FECHA VISITA: " + DateTime.Now.ToShortDateString(), fuente, Brushes.Black, 550, contador1Linea, new StringFormat());

// SEGUNDA LINEA !!!
e.Graphics.DrawString("NOMBRE CLIENTE: " + cliente.Nombres.Trim() + " " + cliente.Apellidos.Trim(), fuente, Brushes.Black, 0, contador2Linea, new StringFormat());

//TERCERA LINEA !!!
e.Graphics.DrawString("DIRECCIÓN: " + cliente.Direccion.Trim(), fuente, Brushes.Black, 0, contador3Linea, new StringFormat());
e.Graphics.DrawString("F. PROX. VISITA: " + DateTime.Now.ToShortDateString(), fuente, Brushes.Black, 550, contador3Linea, new StringFormat());

// CUARTA LINEA
e.Graphics.DrawString("POB./VILLA: " + cliente.PoblacionOVilla.Trim(), fuente, Brushes.Black, 0, contador4Linea, new StringFormat());

//QUINTA LINEA !!!
e.Graphics.DrawString("COMUNA : " + cliente.Comuna.Trim(), new Font("Courier", 8, FontStyle.Regular), Brushes.Black, 0, contador5Linea, new StringFormat());
e.Graphics.DrawString("TELEFONO : " + cliente.Telefono1.Trim(), new Font("Courier", 8, FontStyle.Regular), Brushes.Black, 300, contador5Linea, new StringFormat());

// SEXTA LINEA !!!
e.Graphics.DrawString("TIPO DE DATO : " + cliente.TipoDeDato, fuente, Brushes.Black, 0, contador6Linea, new StringFormat());
e.Graphics.DrawString("EMAIL : " + cliente.Email, fuente, Brushes.Black, 300, contador6Linea, new StringFormat());

// SEPTIMA LINEA DONDE SE SALTA EL ESPACIO
Pen myPen1 = new Pen(Color.Black);
myPen1.DashStyle = DashStyle.Dash;
e.Graphics.DrawLine(myPen1, 800, contador7Linea, 0, contador7Linea);

contador1Linea += 120;
contador2Linea += 120;
contador3Linea += 120;
contador4Linea += 120;
contador5Linea += 120;
contador6Linea += 120;
contador7Linea += 120;
contador8Linea += 120;
}
currentLine += 1;
}
if (textLine != null)
{
e.HasMorePages = true;
}
else
{
e.HasMorePages = false;
}


}