Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Otros entornos y lenguajes > .NET
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

 
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 29-03-2007
mamen mamen is offline
Miembro
 
Registrado: jun 2004
Posts: 80
Poder: 20
mamen Va por buen camino
Problema clase PrintDocument

Hola a todos necesito ayuda urgente, me estoy volviendo loca con este tema. Estoy utilizando la clase PrintDocument para imprimir un archivo q tengo en memoria en un MemoryStream, pero el ejemplo viene en visual basic mis preguntas son:
1. No entiendo cómo relaciona el PrintDocument con el StreamReader.
2. Esta linea de codigo

AddHandler pd.PrintPage, AddressOf Me.pd_PrintPage
cómo se traduce a delphi.

3. Cómo se asocia el parametro ev As PrintPageEventArgs del método pd_PrintPage

Por favor, agradecería que alguien me pudiera ayudar. Muchas gracias por adelantado. El código completo lo adjunto a continuacion.

CODIGO COMPLETO

Código:
Public Class PrintingExample
    Inherits System.Windows.Forms.Form
    Private components As System.ComponentModel.Container
    Private printButton As System.Windows.Forms.Button
    Private printFont As Font
    Private streamToPrint As StreamReader
    
    Public Sub New()
        ' The Windows Forms Designer requires the following call.
        InitializeComponent()
    End Sub    
    
    ' The Click event is raised when the user clicks the Print button.
    Private Sub printButton_Click(sender As Object, e As EventArgs)
        Try
            streamToPrint = New StreamReader("C:\My Documents\MyFile.txt")
            Try
                printFont = New Font("Arial", 10)
                Dim pd As New PrintDocument()
                AddHandler pd.PrintPage, AddressOf Me.pd_PrintPage
                pd.Print()
            Finally
                streamToPrint.Close()
            End Try
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub    
    
    ' The PrintPage event is raised for each page to be printed.
    Private Sub pd_PrintPage(sender As Object, ev As PrintPageEventArgs)
        Dim linesPerPage As Single = 0
        Dim yPos As Single = 0
        Dim count As Integer = 0
        Dim leftMargin As Single = ev.MarginBounds.Left
        Dim topMargin As Single = ev.MarginBounds.Top
        Dim line As String = Nothing
        
        ' Calculate the number of lines per page.
        linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics)
        
        ' Print each line of the file.
        While count < linesPerPage
            line = streamToPrint.ReadLine()
            If line Is Nothing Then
                Exit While
            End If      
            yPos = topMargin + count * printFont.GetHeight(ev.Graphics)
            ev.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, yPos, New StringFormat())
            count += 1
        End While
        
        ' If more lines exist, print another page.
        If Not (line Is Nothing) Then
            ev.HasMorePages = True
        Else
            ev.HasMorePages = False
        End If
    End Sub

Última edición por __hector fecha: 29-03-2007 a las 20:10:58.
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Instanciar Clase buildero_d OOP 2 05-10-2006 06:12:56
Variables de clase supermilloriver OOP 11 28-08-2006 23:03:40
Problema con Clase pelaorb68 OOP 7 27-07-2006 04:57:57
...la clase... Jure Humor 0 27-07-2004 20:00:47
Clase de Catellano Investment Humor 0 30-09-2003 13:59:22


La franja horaria es GMT +2. Ahora son las 18:44:21.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi