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);
}
精彩评论