Questa non è esattamente una risposta completa, ma qui è un pezzo di codice che prende uno screenshot (un bitmap) di un controllo Pannello scorrevole su un modulo. Il grande svantaggio sono i tremolii dello schermo mentre viene scattata la schermata. L'ho provato su semplici app, quindi potrebbe non funzionare in tutti i casi, ma potrebbe essere un inizio.
Ecco come usarlo:
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");
}
}
E qui è il programma di utilità:
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);
}
}
fonte
2013-01-02 09:54:53
Non è una vittima precisa, ma il problema è fondamentalmente lo stesso. Non c'è una soluzione facile qui. Quello che vuoi stampare in realtà non esiste (in quanto non è stato disegnato). Dovresti far scorrere il modulo e acquisire più immagini prima di stampare. Potrebbe essere più semplice stampare semplicemente i dati senza preoccuparsi troppo della corrispondenza esatta del modulo. –
@JonB - beh, questo tipo di domanda potrebbe aiutare a trovare una risposta generale a questo problema ricorrente. Il possibile duplicato non sembra applicarsi molto bene. "Non è possibile", l'unica risposta a questo su SO? –