I have a serious problem here. Iam programming a tool in which the user can design a Control Cubicle for a switchgear. The Cubicle is drawn with Panels and Pictureboxes, which is working nice and looks good.
Now I want to make an Export function which exports the designed Cubicle into an pdf file.
So far so good, the function works - on my computer only! I use CopyFromScreen to get a Screenshot of the Panel in which the cubicle is shown, save that into a file and put it into a pdf file ( I also tried to get a picture of the panel using DrawToBitmap, but this isnt working properly as it is drawing some Pictureboxes over others). On my computer it captures the panel correctly and shows the correct picture in the pdf, however on every other computer it takes a picture of what is behind the Form. This is quite confusing as I have no idea why it should do that and why it is working on my system. So far I tried a few things to force the window to be on top but nothing will work, everybody gets pictures of the desktop or the window that is behind.
Code:
void takeScreenshot()
{
this.TopMost = true;
this.BringToFront();
this.Focus();
Application.DoEvents();
System.Drawing.Rectangle bounds = Mainpanel.Bounds;
bounds.Width = bounds.Width - 6;
bounds.Height = bounds.Height - 4;
using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
{
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(Mainpanel.PointToScreen(new Point()).X + 3, Mainpanel.PointToScreen(new Point()).Y + 2, 0, 0, bounds.Size);
}
bitmap.Save(Application.StartupPath + "\\data\\programdata\\temppic.bmp");
}
this.TopMost = false;
}
Iam actually quite desperate, without the export the program is useless.
Does anyone have an idea how to solve this?
Jonathan