开发者

How to export Image of my form c#

I need a soluti开发者_开发知识库on how could i make a Print Screen of my WinForm on C# and export it as PNG.

Bests


I think this blog post will help.

using (Bitmap bitmap = new Bitmap(ParentForm.Size.Width, ParentForm.Size.Height))
{
    using (Graphics g = Graphics.FromImage(bitmap))
    {
      g.CopyFromScreen(new Point(ParentForm.DesktopLocation.X, ParentForm.DesktopLocation.Y), new Point(0, 0), ParentForm.Size);
    }

    bitmap.Save(@"C:\test.jpg", ImageFormat.Jpeg);
}


Never tried it, but i'd think you should be able to call OnPaint(args) with a PaintEventArgs you create, that includes a Graphics for the image you want to draw on, and the ClipRectangle encompassing the whole area of the form.

This would only work if your form properly processes paint messages (ie: if it stores enough info to be able to repaint the window fully at will), and it may only get the client area (ie: it might not get the title bar or menus).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜