Results 1 to 2 of 2

Thread: Passing Image to PrintPreviewDialog

  1. #1

    Thread Starter
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472

    Passing Image to PrintPreviewDialog

    Hi guys,
    I have a problem here, I have an image from certain file path. Now what I want to do is to pass that image to the printpreviewdialog in order to show that image and I don't know where to continue with this sample code:

    VB Code:
    1. private void button1_Click(object sender, System.EventArgs e)
    2.         {          
    3.             PrintPreviewDialog t = new PrintPreviewDialog();
    4.             printDocument1.PrintPage += new PrintPageEventHandler(pr);
    5.             t.Document = printDocument1;
    6.            
    7.             t.ShowDialog();
    8.            
    9.         }
    10.  
    11.         private void pr(object sender, PrintPageEventArgs e)
    12.         {
    13.             // where source image came from
    14.             Image i = Image.FromFile("C:\\idBack.jpg");
    15.             i.Dispose();
    16.         }
    It appears to be blank paper, I know there's missing here.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Passing Image to PrintPreviewDialog

    The second argument to the PrintPage event handler has a Graphics property. You use this object to draw whatever you want on the printing surface. In your case you would call its DrawImage method. The printing surface is usually the paper in the printer but in the case of a PrintPreviewDialog it is the PrintPreviewControl that it contains.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width