Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

Help with printing a form

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
donotdespisethesnake
Asked:
donotdespisethesnake
  • 3
  • 3
1 Solution
 
Éric MoreauSenior .Net ConsultantCommented:
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
 
donotdespisethesnakeAuthor Commented:
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
 
Éric MoreauSenior .Net ConsultantCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
donotdespisethesnakeAuthor Commented:
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
 
Éric MoreauSenior .Net ConsultantCommented:
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
 
donotdespisethesnakeAuthor Commented:
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now