Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Saving a panel with graphic lines to .jpg

I have made this application which resembles, and i want to be able to save anything i draw on a panel. However when I try to use my already existing code it saves a blank image, I have read somewhere that a Bitmap doesn't pick up child buttons, not sure how to fix this though.

Any help would be appreciated.

private void Save_Click(object sender, EventArgs e)
    {
        int picWidth = this.panel1.Width;
        int picHeight = this.panel1.Height;

        var graphics = Form1.g;

        Bitmap bm = new Bitmap(picWidth, picHeight);

        SaveFileDialog sf = new SaveFileDialog();
        sf.Filter = "JPEG Image (.jpeg) | *.jpg";

        panel1.DrawToBitmap(bm, new Rectangle(0, 0, picWidth, picHeight));

        sf.ShowDialog();

        graphics.DrawImage(bm, Point.Empty);

        var path = sf.FileName;

        bm.Save(path, ImageFormat.Jpeg);
    }

Comments