Solved

Help with printing a form

Posted on 2008-06-19
6
185 Views
Last Modified: 2011-10-19
I need a simple "Alt-prtscrn" style print of mu form, so I am using code from http://msdn.microsoft.com/en-us/library/aa287529(VS.71).aspx to print a C# form. This works Ok, except that I am invoking the printButton_Click method from a File|Print menu and parts of the menu overlay the capture image.

What is the quick/simple way to avoid the menu appearing in the printed image ?

A web search reveals numerous examples but none address my particular issue. I'm open to other methods of printing but I don't really want to write code to render individual controls.
0
Comment
Question by:donotdespisethesnake
  • 3
  • 3
6 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 21821575
even if you are in C#, you can use the VB PowerPacks 3.0 controls. It let you hides some controls before printing. See http://www.emoreau.com/Entries/Articles/2008/03/Microsoft-Visual-Basic-Power-Packs-30.aspx
0
 

Author Comment

by:donotdespisethesnake
ID: 21822027
Those controls are nice (print preview!),. but the PrintForm has exactly the same problem! The File menu appears in the captured image.

How can I hide the File menu before printing?
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 21822140
it is explained in my article:
"Any control that is not visible is not rendered on the output. This is useful if you want to hide some controls. You simply need to set them to invisible, use the Print method and set them visible back again."

            Me.MenuStrip1.Visible = False
            .Print(Me, PowerPacks.Printing.PrintForm.PrintOption.FullWindow)
            Me.MenuStrip1.Visible = True
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:donotdespisethesnake
ID: 21823806
I guess I didn't explain well, the picture might help. The leftover graphics is from the activation of the File menu, hiding the menustrip doesn't help with that


image.JPG
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 21824214
I have this code, in the click event of a menu item, and I don't have your side effect. My code is:

    Private Sub PrintToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripMenuItem.Click
        'btnPrint.PerformClick()
        With PrintForm1
            .PrintAction = Printing.PrintAction.PrintToPreview

            Me.MenuStrip1.Visible = False
            .Print(Me, PowerPacks.Printing.PrintForm.PrintOption.FullWindow)
            Me.MenuStrip1.Visible = True
        End With
    End Sub

What is your code?
0
 

Accepted Solution

by:
donotdespisethesnake earned 0 total points
ID: 21824636
Ok, I found a simple solution. I just need to put "this.Refresh()" before I capture the screen. This allows the form to repaint itself.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Problem!!! 8 37
Release Dynamically Allocated Memory in C# 3 38
VS2013 publish C# application Created folder -- where is it??? 10 28
itextsharp with c# 3 10
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question