이것은 완전한 대답은 아니지만 다음은 Form에서 스크롤 가능한 Panel 컨트롤의 스크린 샷 (비트 맵)을 사용하는 코드입니다. 큰 단점은 스크린 샷이 찍히는 동안 화면이 깜박입니다. 간단한 앱에서 테스트 했으므로 어떤 경우에도 작동하지 않을 수도 있지만 시작일 수 있습니다. 여기
은 그것을 사용하는 방법은 다음과 같습니다
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");
}
}
을 그리고 여기에 유틸리티입니다 :
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);
}
}
그것은 정확한 속는 아니지만, 문제는 근본적으로 동일합니다. 여기에는 쉬운 해결책이 없습니다. 인쇄하려는 것은 실제로 존재하지 않습니다 (그리지 않았으므로). 인쇄하기 전에 양식을 스크롤하고 여러 이미지를 캡처해야합니다. 양식을 정확히 일치시키는 것에 대해 걱정하지 않고 데이터를 인쇄하는 것이 더 쉬울 수도 있습니다. –
@ 존 B - 음, 이런 종류의 질문은이 반복적 인 문제에 대한 일반적인 대답을 찾는 데 도움이 될 수 있습니다. 가능한 복제본이 실제로 적용되지 않는 것 같습니다. 이렇게 "SO가 가능하지 않다"는 유일한 대답은 무엇입니까? –