C#Windows窗体控件的图像? [英] C# Windows form Control to Image?

查看:95
本文介绍了C#Windows窗体控件的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个面板的图像并将其保存到一个文件夹。问题是,面板上有滚动条和生成的图像只对​​面板的可见部分。

I am trying to create an image of a Panel and save it to a folder. The problem is the panel has scrollbars and the image generated is only for the visible portion of the Panel.

我使用的代码是一样的东西Panel.DrawToImage。难道有任何帮助,在这里保存整个面板为一个图片,而不仅仅是可见部分?

The code I use is something like Panel.DrawToImage. Could there be any help out here to save the entire Panel as a picture and not just the visible portion?

推荐答案

没有快乐的答案在这里,DrawToBitmap只能画,这将是对用户可见。技巧像改变面板的位置和大小,通常事先很快出来的气体由于在由父所施加的控制大小的限制运行。窗体本身永远不能比屏幕大,现在你还会依赖于目标计算机上的视频适配器的分辨率。

No happy answers here, DrawToBitmap can only draw what would be visible to the user. Tricks like changing the Location and Size of the panel beforehand usually quickly run out of gas due to the restriction on the control size imposed by the parent. The form itself can never get larger than the screen, now you'll also depend on the resolution of the video adapter on the target machine.

一个丑陋的黑客是运行DrawToBitmap多次,改变每个调用之间小组AutoScrollPosition属性。你不得不拼接产生的图像在一起。要特别注意当然,由于它不会像其他的人一样大的最后一个。

One ugly hack is to run DrawToBitmap multiple times, changing the Panel's AutoScrollPosition property between each call. You'd have to stitch the resulting images together. Paying special attention to the last one of course since it won't be as large as the other ones.

一旦你开始考虑这样的代码,你真的应该思考有关的PrintDocument或报表生成器来代替。一个好处那就是打印输出看起来会heckofalot清洁。打印屏幕截图都不约而同地丑陋由于视频和打印机分辨率的巨大差异。

Once you start considering code like this, you really ought to think about PrintDocument or a report generator instead. One benefit to that is that the printout will look a heckofalot cleaner. Printed screen-shots are invariably ugly due to the huge difference in video and printer resolution.

这篇关于C#Windows窗体控件的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆