0
I created a button with button24_Click_1
to take printscreen from 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");
}
}
Follow the problem:
Follow Quickwacth error:
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 image, Rectangle rect) in System.Windows.Forms.PictureBox.Onpaint(Painteventargs pe) 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) in 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)
Coded bmp.Save();
works perfectly, I just can’t add the photo directly to picturebox1
. What I did wrong and how to fix ?
I would need to see more details, I don’t even know where the error is occurring. It is possible that the
Bitmap
is not generating an object. Anyway this code must give error, because it creates the object withusing
, keeps it in a property of another object and ends the execution by releasing the object, when accessing this property the object no longer exists.– Maniero
@Maniero see the answer :)
– Matheus Miranda