DrawToBitmap没有截取所有项目的截图 [英] DrawToBitmap not taking screenshots of all items

查看:203
本文介绍了DrawToBitmap没有截取所有项目的截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在StackOverflow上找到了这个有用的代码:

I currently have this useful code that I found elsewhere on StackOverflow:

form.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));

我有一个带有几个文本框/下拉菜单和一个大图片框的表单。然后我在这个大图片框的顶部放置了较小的图片框。

I have a form with a few text boxes/drop downs and a large picture box. I then have smaller picture boxes placed on top of this large picture box.

当我查看截图时,它会显示表格,但是放在大图片框上的较小的图片框由于某种原因不显示?

When I view the screenshot taken, it shows the form but the smaller picture boxes that have been placed over the large picture box are not displayed for some reason?

推荐答案

我在Control.DrawToBitmap()的文档中看到了这个限制:

I see this limitation in the docs for Control.DrawToBitmap():


容器内的控件以相反的顺序呈现。

Controls inside containers are rendered in reverse order.

这意味着如果两个控件相互重叠,通常呈现在另一个下面(首先绘制然后由重叠控件透支)的那个将改为最后渲染(因此它将与通常重叠的那个重叠)。在你的情况下,一个较小的控件被完全绘制在一个较大的控件的边界内并且在它的顶部,控件将被这个反向渲染隐藏。

That would mean that if two controls overlap each other, the one normally rendered "underneath" the other (it's drawn first and then overdrawn by the overlapping control) will instead be rendered last (so it will overlap the one that normally overlaps it). In your case, where a smaller control is drawn wholly inside the bounds of a larger one and on top of it, the control will be hidden by this reverse rendering.

尝试通过在较大的PictureBox上使用BringToFront()和SendToBack()来解决这个问题。在绘制到位图之前调用BringToFront(),然后在完成后调用SendToBack()。如果您不希望用户看到屏幕闪烁,请在进行任何Z顺序更改之前尝试调用SuspendLayout(),然后在重置为正确的Z顺序后调用ResumeLayout(true)。

Try working around this by using BringToFront() and SendToBack() on the larger PictureBox that is being overlapped by the smaller ones. Call BringToFront() just before drawing to the bitmap, then SendToBack() when you're done. If you don't want the user to see the screen flicker, try calling SuspendLayout() before making any Z-order changes, then ResumeLayout(true) after resetting to the proper Z-order.

这篇关于DrawToBitmap没有截取所有项目的截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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