如何使用 C# 将 Windows 窗体面板作为位图获取?
我有一个 Windows 窗体,其中一个面板上有多个控件。面板并不占据所有的表单空间,而只占据一小部分。我想知道是否有某种方法可以将面板(带有所有子控件)的显示检索为位图。就像屏幕截图一样,但仅裁剪到面板。
我没有查看屏幕截图,因为该面板位于可滚动控件(DevX 控件)内,因此有时它可能不完全可见,我需要其视觉表示(无论是否可见)。
这有可能吗?
编辑:
好吧,现在看来正如我所担心的那样。建议使用 DrawToBitmap() 的解决方案仅绘制控件的可见部分。我使用 DisplayRectangle 来检索完整控件的大小。矩形就可以了,现在位图是完整控件的大小,但是控件不可见的部分在位图上是透明的,不显示控件不可见部分上的控件。
有没有机会完全渲染出来?
I have a Windows form with a panel with several controls on it. The panel does not take up all of the form space, but only a small part. What I want to know is if there is some way to retrieve the display of the panel (with all child controls) as a bitmap. Like a screenshot but only cropped to the panel.
I am not looking into the screen capture because the panel is within the scrollable control (DevX controls) so at times it may not be fully visible and I need its visual representation whether visible or not.
Is this possible at all?
Edit:
Well, now it seems that it was as I feared. The suggested solution with DrawToBitmap() only draws the part of the control that is VISIBLE. I have used DisplayRectangle to retreive the size of the complete control. The rectangle is ok, and now the bitmap is the size of the complete control, but the part of the control that is NOT VISIBLE is TRANSPARENT on the bitmap, not displaying the controls that are on the invisible part of the control.
Is there any chance for this to be rendered completely?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然,只需使用面板的 DrawToBitmap() 方法即可。它不是 100% 可靠,面板上可能有不支持它的控件。例如 RichTextBox、WebBrowser 或某种第 3 方 ActiveX 控件。
Sure, just use the panel's DrawToBitmap() method. It isn't 100% reliable, there might be controls on the panel that don't support it. Like RichTextBox, WebBrowser or some kind of 3rd party ActiveX control.