Click here to Skip to main content
Licence CPOL
First Posted 24 Dec 2006
Views 24,219
Bookmarked 22 times

Print Using the Windows Fax and Picture Preview

By | 17 Jan 2007 | Article
Calling the Windows Print and Fax Viewer from a shell command is an elegant way to solve most of your .NET image print issues.

Introduction

I often admired the Windows Print and Fax Viewer for printing images. I often would ignore the individual application's print facilities and go to the Windows Print and Fax Viewer for printing images. If you want to add an excellent print facility to your project, the following code will do that:

'------------------------------------------------------------------------------
'PREVIEW AND PRINTING A BITMAP 
'______________________________________________________________________________

Private Sub PrintPreviewToolStripMenuItem_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles PrintPreviewToolStripMenuItem.Click

    ' create unique file in directory so load Print and Fax is minimized
    ' This project has a directory reserved for preview,
    ' this avoids loading multiple previews which causes delay

    ' a file is required so a preliminary save of bitmap
    ' is made which isnt a bad preprint philosophy
    bm.Save(D2007DirDefault & "\prj\PrintScratch\PrintPreview.bmp")

    Dim procid
    procid = Shell("rundll32.exe C:\WINDOWS\System32\shimgvw.dll," & _ 
                   "ImageView_Fullscreen " & _
                   D2007DirDefault & "\prj\PrintScratch\PrintPreview.bmp")

End Sub

'----------------------------------------------------------
'Previewing a predetermined directory
'____________________________________________________

Private Sub PreviewDesignsWindowsPictureAndFaxViewerToolStripMenuItem_Click(_
        ByVal sender As System.Object, ByVal e As System.EventArgs) _
        Handles PreviewDesignsWindowsPictureAndFaxViewerToolStripMenuItem.Click
    Dim procid
    procid = Shell("rundll32.exe C:\WINDOWS\System32\shimgvw.dll," & _
                   "ImageView_Fullscreen " & _
                   SObj.DP.designs ' directory with images)
End Sub

'---------------------------------------------------------------------------------
'Previewing a user selected Directory
'---------------------------------------------------------------------------------

Private Sub SelectDirectoryToPreviewWindowPictureAndFaxViewerToolStripMenuItem_Click(ByVal _
        sender As System.Object, ByVal e As System.EventArgs) Handles _
        SelectDirectoryToPreviewWindowPictureAndFaxViewerToolStripMenuItem.Click
    Dim newfile As String
    Me.FolderBrowserDialog1.ShowNewFolderButton = False
    Me.FolderBrowserDialog1.SelectedPath = "C:\"
    If Me.FolderBrowserDialog1.ShowDialog() <> DialogResult.OK Then Exit Sub
    newfile = Me.FolderBrowserDialog1.SelectedPath
    Dim procid
    procid = Shell("rundll32.exe C:\WINDOWS\System32\shimgvw.dll," & _ 
                   "ImageView_Fullscreen " & newfile)
End Sub

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

dmm12

Web Developer

United States United States

Member

Started in IT in 1959 working on Electronic accounting machines.
 
Worked through wiring panels and card systems.
 
1963-1965 USArmy
1961-1975 Computer Supervisor Contental Can
1975-1998 Data Force Incorporated - President
1998-2006 IT Director Promotions Unlimited Corp
2007 retired, project DesignLab(C)2007
 
Design and concept rules, coding is a required evil
 


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralDirectly printing to default printer Pinmembertrucido792:41 24 Jun '08  
Questionbm ? Pinmemberdibblm-Ohio3:56 6 Feb '07  
AnswerRe: bm ? Pinmemberdmm124:58 6 Feb '07  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120517.1 | Last Updated 18 Jan 2007
Article Copyright 2006 by dmm12
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid