c# - How to save and load in panel? -


i want save image panel bitmap , want load saved image after form comes out of minimizing mode.

bitmap bmp = new bitmap(panel1.width, panel1.height); panel1.drawtobitmap(bmp, panel1.bounds); bmp.save(@"c:\test"); panel1.backgroundimage = image.fromfile(@"c:\test"); 

and event should use minimizing event? p.s. c# beginner.

edited

drawing panel's contents. should done inside paint event handler, this:

private void panel1_paint(object sender, painteventargs e) {     using (pen p = new pen(color.red, 3))     {         // panel's graphics instance         graphics gr = e.graphics;          // draw panel         gr.drawline(p, new point(30, 30), new point(80, 120));         gr.drawellipse(p, 30, 30, 80, 120);     } } 

saving panel's contents image. part should done somewhere else (for example, when click on "save" button):

private void savebutton_click(object sender, eventargs e) {      int width = panel1.size.width;      int height = panel1.size.height;       using (bitmap bmp = new bitmap(width, height))      {          panel1.drawtobitmap(bmp, new rectangle(0, 0, width, height));          bmp.save(@"c:\testbitmap.jpeg", imageformat.jpeg);      } } 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -