Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
PictureBox picture00 = new PictureBox();
picture00.SizeMode = PictureBoxSizeMode.StretchImage;
picture00.Image = new Bitmap(Application.StartupPath + "\\pic.jpg");
picture00.Location = new System.Drawing.Point(145, 172);
picture00.Size = new System.Drawing.Size(88, 130);
pictureBox1.Controls.Add(picture00);
Posted

Assuming that saving an image of the entire visual contents of the Panel is your goal:
C#
// be sure you include these:
using System.Drawing;
using System.Drawing.Imaging;

// assume there's a Button named 'SavePanel1Contents
private void SavePanel1Contents_Click(object sender, EventArgs e)
{
    int width = panel1.Width;
    int height = panel1.Height;

    Bitmap bitMap = new Bitmap(width, height);

    panel1.DrawToBitmap(bitMap, new Rectangle(0, 0, width, height));

    // using .png format here: there are many other formats you can save as
    bitMap.Save(@"C:\Users\YourUserName\Desktop\TestSaveImageOfPanel1.png", ImageFormat.Png);
}
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 14-Sep-14 11:49am    
5ed. I also added my answer to address a different aspect of the question: why PictureBox should not be used in this case.
—SA
In addition to Solution 1:

You should not use the class PictureBox. This control is purely redundant, designed to help developers in some simplest cases. If you use it in your case, it won't be helpful, will only force your to use some extra resources and waste development time. What to do? Please see my past answers:
Append a picture within picturebox[^],
draw a rectangle in C#[^],
How do I clear a panel from old drawing[^],
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
capture the drawing on a panel[^],
Drawing Lines between mdi child forms[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900