Visualizzazione dei risultati da 1 a 7 su 7
  1. #1

    [VB.NET]Stampare un file .txt senza aprirlo

    Ciao a tutti, sapete dirmi in che modo posso stampare un documento di testo (txt) senza aprirlo?

    piu' o meno il mio ragionamento è così

    "se si verifica questo stampa questo file, se si verifica altro stampa quest'altro file."

    spero di essere stato chiaro.
    grazie anticipate

  2. #2
    Utente di HTML.it
    Registrato dal
    May 2004
    Messaggi
    134
    prova:
    shell "print file.txt",vbHide

  3. #3
    Utente di HTML.it
    Registrato dal
    May 2004
    Messaggi
    134
    scusa la risposta era per vb6. Il concetto comunque è lo stesso.

  4. #4
    no putroppo non va

  5. #5
    Ciao ,
    non so se ti serve ma puoi provare così :

    Sul click di un bottone inserisci questo codice :
    codice:
            Dim Pd As Printing.PrintDocument
            Try
                streamToPrint = New System.IO.StreamReader(Nome_del_tuo_file)
                Try
                    printFont = New Font("Arial", 10)
                    Pd = New Printing.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
    e poi scrivi questa sub :

    codice:
    Private Sub pd_PrintPage(ByVal sender As Object, ByVal ev As Printing.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
    Dovrebbe funzionare !!!
    Il report è andato ?
    Ciao alla prossima
    Cordiali saluti
    Red Roma

  6. #6
    Perfetto thx

    Per red = mi sono dimenticato di mandarti una email di ringraziamento, grazie!

  7. #7
    Benissimo , alla prossima .
    Red
    Cordiali saluti
    Red Roma

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.