I created a button with button24_Click_1
to take printscreen of Form1:
private void button24_Click_1(object sender, EventArgs e)
{
var frm = new Form1();
using (var bmp = new Bitmap(frm.Width, frm.Height))
{
frm.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
pictureBox1.Image = bmp;
//bmp.Save(@"C:\Users\Matheus Miranda\Desktop\TESTE\screen.png");
}
}
Here's the problem:
FollowingisaQuickWactherror:
Message:"Invalid parameter."
ParamName: null
StackTrace: in System.Drawing.Image.get_RawFormat () in System.Drawing.Graphics.DrawImage (Image image, Int32 x, Int32 y, Int32 width, Int32 height) in System.Drawing.Graphics.DrawImage (Image image, Rectangle rect) in System.Windows.Forms.PictureBox.OnPaint (PaintEventArgs) in System.Windows.Forms.Control.PaintWithErrorHandling (PaintEventArgs and Int16 layer) in System.Windows.Forms.Control.WmPaint (Message & m) in System.Windows.Forms.Control.WndProc (Message & m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage (Message & m) in System.Windows.Forms.Control.ControlNativeWindow.WndProc (Message & m) in System.Windows.Forms.NativeWindow.DebuggableCallback (IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
With code bmp.Save();
works perfectly, I just can not add the direct photo to picturebox1
. What did I do wrong and how to fix it?