开发者

Parent call to Control.DrawToBitmap does not seem to respect clipping region set in child control

开发者 https://www.devze.com 2023-02-14 22:15 出处:网络
I have created a UserControl which simp开发者_如何学Cly defines a new GraphicsPath and sets that to be the Region of the control. Its primary use is to act as a backdrop for other controls so typicall

I have created a UserControl which simp开发者_如何学Cly defines a new GraphicsPath and sets that to be the Region of the control. Its primary use is to act as a backdrop for other controls so typically the only thing set on it is BackColor. When I call DrawToBitmap on the control's parent, the child control is drawn as a rectangle rather than getting clipped to region I expected. Am I missing something here?

Standard use of the control does not exhibit this problem.

Also, I need to be able to draw this control to an image while it is not currently shown on screen. I have seen some workarounds would could have worked had I not had this additional requirement.


DrawToBitmap does not honor regions. But Graphics.CopyFromScreen does.

        Bitmap bitmap = new Bitmap(this.Width, this.Height);
        using (Graphics graphics = Graphics.FromImage(bitmap))
        {
            graphics.CopyFromScreen(this.Location, new Point(0, 0), this.Size);
        }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号