Link to home
Start Free TrialLog in
Avatar of judico
judico

asked on

Printing a Form in VB.NET

Suppose you have a form open on the screen which takes up only a part of it. How can one print this form, i.e. have a screenshot only of the part of the screen where the form is?
Avatar of DotNetLover_Baan
DotNetLover_Baan

Avatar of judico

ASKER

Thanks for the link. The example, however, doesn't seem to be written in VB.NET.
Double click on the PrintDocument to get to the  "PrintDocument1_PrintPage" event handler.

-Baan
Avatar of judico

ASKER

These links also don't seem to solve the problem. It appears that they concern printing of a document and not printing of a screenshot of the form displayed on the screen.
Hi,
have a look at this article
http://www.vb-helper.com/howto_net_print_form_image.html

Hope that this helps you

Regards,
venki
Avatar of judico

ASKER

Thanks for the link. For some reason, however, I can't declare PrintDocument1. The following

Private WithEvents m_PrintDocument As PrintDocument1

gives me the error message

Type 'PrintDocument1' is not defined.

despite the fact that I have installed the PrintDocument1 object from the ToolBox. What might be the reason?
ASKER CERTIFIED SOLUTION
Avatar of iboutchkine
iboutchkine

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Howard Cantrell
Howard Cantrell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of judico

ASKER

planocz, this part of your code:

Private Sub pdoc_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles pdoc.PrintPage
        e.Graphics.DrawImage(memoryImage, 0, 0)
End Sub

gives me the following error:

Handles clause requires a WithEvents variable.

Do you have any suggestions how to fix that?
Sorry I forgot to add this to your FORM...
 
  Private WithEvents pdoc As New PrintDocument
Avatar of judico

ASKER

iboutchkine and  planocz,

Thank you so much for the help. I want to give points to both of you. How can I do that?

judico
Avatar of judico

ASKER

iboutchkine and  planocz,

I just sent 250 points to each one of you. Please let me know if there was any problem in receiving the points. Thanks again for the help.

judico
I hope it will help me as well, thats some great work guys. Keep it UP !!
Hi Guys

The above are great if you only want to capture the visible part of the screen - how would you work this if your form was longer than the screen and you used the scrollbar to move down it?  ( I have this issue at the moment!)

Regards,

Dave