A very simple and straight forward solution exists, has been thought of by Microsoft and includes these steps:
- Instead of
PictureBox
use a Panel
and instead of using the Image
property of the PictureBox
use the BackgroundImage
property of the Panel
note: By using also the BackgroundImageLayout
property you can quite easily instruct the Panel
to stretch, center or zoom the image (I'm presuming the default value which is tile is not a good option in your case)
- Instead of placing the other user controls at higher Z order but alongside the previous
PictureBox
place them inside the Panel
Use the Control.DrawToBitmap
method like so:
private void button1_Click(object sender, EventArgs e) {
var bmp = new Bitmap(this.panel1.Width, this.panel1.Height);
this.panel1.DrawToBitmap(bmp, new Rectangle(Point.Empty, bmp.Size));
bmp.Save(@"D:\test.png", ImageFormat.Png);
}
That will result in your controls begin rendered along with the picture:
Furthermore, and if your scenario allows it, you could simply use the DrawToBitmap
method with any control which contains all of the actors you wish to render, for instance the actual Form
.