Search code examples
c#printscreen

How to export Image of my form c#


I need a solution how could i make a Print Screen of my WinForm on C# and export it as PNG.

Bests


Solution

  • 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);
    }