c# - 如何在 Windows 窗体 C# 中打印可滚动面板

标签 c# winforms screenshot

我有一个自定义控件,它有一个可滚动面板,整个内容在屏幕上不可见。(需要滚动才能看到所有内容)

用户希望打印面板与它在屏幕上的外观完全一样,但用户想要整个面板,如果不滚动则在屏幕上不可见。

如何在多个页面中捕获和打印整个面板?

感谢任何帮助。

最佳答案

这可能对你有帮助。

    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/

相关文章:

c++ - 如何防止我的屏幕截图制作控制台程序阻止屏幕截图?

Java 通过套接字发送屏幕截图

c# - 在 C# 中用双引号替换转义字符

c# - 网络浏览器是否需要在客户端机器上安装 IE

异步任务中的 C# 更改标签文本

c# - 从记事本保存和检索数据时遇到奇怪的事情

c# - 以编程方式添加到 FlowLayoutPanel 的项目不像设计时那样对齐

c# - 如何避免具有潜在危险的 Request.Form 值?

c# - winforms饼图中的百分比总和超过100%

linux - 在 Fedora (Linux) 中自动将屏幕截图复制到剪贴板