Print the shape of the window with the ability to scroll.

Possible duplicate:
How to take a screenshot using a Winforms control in C #?

I have a window form with a list of names and images. The list is long, so there is a scroll bar for it. Now I would like to print this form, but I can’t, because the print function prints only the β€œvisible” part, since the invisible part is displayed when scrolling down. So, is there a way to print the entire form at once?

+7
source share
2 answers

Locate the print control in the Visual Basic PowerPacks toolbar.

To print the entire client area of ​​a scrollable form, try this ...

1. On the toolbar, go to the "PowerPacks" tab of Visual Basic, and then drag the PrintForm component onto the form.

The PrintForm component will be added to the component tray.

2. In the Properties window, set the PrintAction property to PrintToPrinter.

3. Add the following code to the appropriate event handler (for example, to the Click event handler for the print button).

1.PrintForm1.Print (Me, PowerPacks.Printing.PrintForm.PrintOption.Scrollable)

Give this snapshot and let me know how it works for you.

+3
source

This is not a complete answer, but here is a piece of code that takes a screenshot (bitmap) of the scrollable Panel control in the form. The big drawback is the flickering of the screen while taking a screenshot. I tested it on simple applications, so it may not work in all cases, but this may be the beginning.

Here's how to use it:

public partial class Form1 : Form { public Form1() { InitializeComponent(); // create a scrollable panel1 component } private void button1_Click(object sender, EventArgs e) { TakeScreenshot(panel1, "C:\\mypanel.bmp"); } } 

And here is the utility:

  public static void TakeScreenshot(Panel panel, string filePath) { if (panel == null) throw new ArgumentNullException("panel"); if (filePath == null) throw new ArgumentNullException("filePath"); // get parent form (may not be a direct parent) Form form = panel.FindForm(); if (form == null) throw new ArgumentException(null, "panel"); // remember form position int w = form.Width; int h = form.Height; int l = form.Left; int t = form.Top; // get panel virtual size Rectangle display = panel.DisplayRectangle; // get panel position relative to parent form Point panelLocation = panel.PointToScreen(panel.Location); Size panelPosition = new Size(panelLocation.X - form.Location.X, panelLocation.Y - form.Location.Y); // resize form and move it outside the screen int neededWidth = panelPosition.Width + display.Width; int neededHeight = panelPosition.Height + display.Height; form.SetBounds(0, -neededHeight, neededWidth, neededHeight, BoundsSpecified.All); // resize panel (useless if panel has a dock) int pw = panel.Width; int ph = panel.Height; panel.SetBounds(0, 0, display.Width, display.Height, BoundsSpecified.Size); // render the panel on a bitmap try { Bitmap bmp = new Bitmap(display.Width, display.Height); panel.DrawToBitmap(bmp, display); bmp.Save(filePath); } finally { // restore panel.SetBounds(0, 0, pw, ph, BoundsSpecified.Size); form.SetBounds(l, t, w, h, BoundsSpecified.All); } } 
+2
source

All Articles