print preview timing issue?

  • Thread starter Thread starter Rosco5737
  • Start date Start date
R

Rosco5737

Guest
Hi all, I am having a little trouble with the print preview dialogue and the print screen command (PRTSC) and looking for a little insight.

I have a Chart from MSChart controls displayed on my application. I want to display this chart in a print preview dialogue so it can be printed. Since I have no idea how to print the chart itself, I am trying to just call print screen and then print the bitmap. Here is my relevant code:

Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem4.Click
'print preview
Dim ppd As New PrintPreviewDialog()
ppd.Document = throughprint
ppd.ShowDialog()
end sub

Private Sub throughprint_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles throughprint.PrintPage
'throughprint printpage
Dim s As SendKeys
Dim timage As Image
s.Send("{PRTSC}")
Dim picdata As IDataObject = Clipboard.GetDataObject()
pimage = picdata.GetData(DataFormats.Bitmap)
e.Graphics.DrawImage(timage, 120, 90)
end sub



The problem is the print preview displays different images every time I call it. For example, it usually with display just the "generating previews" screen that pops up when print preview is selected. Sometimes it shows part of my chart, other times the whole thing. It sometimes layers images on top of each other if print preview is opened a few times. It seems to me to be a timing issue with what and when PRTSC actually gets called. I've tried useing SENDWAIT with the same results. Has anyone had this problem or know the solution; or should be trying something completely different? This post might be related to the post shootsnlad however I can get whatever is displayed on my preview screen to print fine so I'm not sure. Anyway, thanks much...
 
Simple as that, thanks.

PS For anyone out there interested in this post here's a minor problem I ran into after what Crazed Lunatic posted. My Print Preview was a menu item like most applications, however, using the standard menu item control from the tool box creates menus that fade when they are clicked. This results in a ghosted image of your menu and your application when you print out the screen so you will need to sleep for a about a quarter of a second in order to let the menu completely fade out before you print screen.
 
thanks

Just wanted to say "thanks" to Rosco. By combining what I had with using the Print Dialog box, I was able to get my printscreen to work as well. Thanks for the help...
 
Back
Top