delete file problem

A

apple_yap

i try to print image file in a directory using PrintDocument. It will raise
printPage event to draw image to the printer. The file will be deleted after printing and the directory will be checked every second to get new file inside it.
Where should i do the delete function? The way to print image is get from msdn. Can tell me where can i refer to other better ways to print the image file.
Thank you.

Below is the code,

Public fileName As String

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Timer1.Enabled = True
End Sub

Sub printImage(ByVal fileName As String)
Dim pd As New PrintDocument
AddHandler pd.PrintPage, AddressOf Me.pd_PrintPage
pd.Print()
End Sub

Private Sub pd_PrintPage(ByVal sender As Object, ByVal ev As
PrintPageEventArgs)
' Draw a picture.
ev.Graphics.DrawImage(Image.FromFile(fileName),
ev.Graphics.VisibleClipBounds)
' Indicate that this is the last page to print.
ev.HasMorePages = False
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Dim dir As New DirectoryInfo("c:\dir")
Dim fi As FileInfo() = dir.GetFiles()
Dim fitemp As FileInfo

For Each fitemp In fi
fileName = fitemp.FullName
printImage(fileName)
Next
End Sub

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 
H

Herfried K. Wagner [MVP]

apple said:
i try to print image file in a directory using PrintDocument. It will raise
printPage event to draw image to the printer. The file will be deleted
after printing and the directory will be checked every second to get new
file inside it.
Where should i do the delete function? The way to print image is get from
msdn. Can tell me where can i refer to other better ways to print the
image file.
[...]
Public fileName As String

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Timer1.Enabled = True
End Sub

Sub printImage(ByVal fileName As String)
Dim pd As New PrintDocument
AddHandler pd.PrintPage, AddressOf Me.pd_PrintPage
pd.Print()
End Sub

Private Sub pd_PrintPage(ByVal sender As Object, ByVal ev As
PrintPageEventArgs)
' Draw a picture.

\\\
Dim img As Image = Image.FromFile(FileName)
ev.Graphics.DrawImage(img)
img.Dispose()
File.Delete(FileName)
///
 
A

apple_yap

thanks..
Inside the print queue, the Document Name is "document" when it is printed. How can i show the actual file name in it?

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 
M

Michael Proctor

DocumentName property of the PrintDocument component, set that before Print
method.

Remember that the document name is for the whole document (all pages)
therefore must be set before the Print method and not during the PrintPage
event.
 
G

Guest

yup, i get it. Thank you.

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top