我有一个自定义控件,它有一个可滚动面板,整个内容在屏幕上不可见。(需要滚动才能看到所有内容)
用户希望打印面板与它在屏幕上的外观完全一样,但用户想要整个面板,如果不滚动则在屏幕上不可见。
如何在多个页面中捕获和打印整个面板?
感谢任何帮助。
最佳答案
这可能对你有帮助。
pnlReport.AutoScrollPosition = new Point(0, 0);
public void DrawControl(Control control, Bitmap bitmap)
{
control.DrawToBitmap(bitmap, control.Bounds);
foreach (Control childControl in control.Controls)
{
DrawControl(childControl, bitmap);
}
}
public void SaveBitmap(string filename)
{
var size = myControl.PreferredSize;
var height = size.Height;
Bitmap bmp = new Bitmap(this.myControl.Width, height);
this.myControl.DrawToBitmap(bmp, new Rectangle(0, 0, this.myControl.Width, height));
foreach (Control control in myControl.Controls)
{
DrawControl(control, bmp);
}
bmp.Save(filename, ImageFormat.Jpeg);
bmp.Dispose();
}
关于c# - 如何在 Windows 窗体 C# 中打印可滚动面板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48705192/