c# - CopyFromScreen returns an image of whatever is behind the Form -


i have serious problem here. iam programming tool in user can design control cubicle switchgear. cubicle drawn panels , pictureboxes, working nice , looks good.

now want make export function exports designed cubicle pdf file.

so far good, function works - on computer only! use copyfromscreen screenshot of panel in cubicle shown, save file , put pdf file ( tried picture of panel using drawtobitmap, isnt working drawing pictureboxes on others). on computer captures panel correctly , shows correct picture in pdf, on every other computer takes picture of behind form. quite confusing have no idea why should , why working on system. far tried few things force window on top nothing work, gets pictures of desktop or window 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 quite desperate, without export program useless.

does have idea how solve this?

jonathan

use code.

void takescreenshot()     {         application.doevents();         system.drawing.rectangle bounds = mainpanel.bounds;         bounds.width = bounds.width - 6;         bounds.height = bounds.height - 4;          using (bitmap bitmap = new bitmap(mainpanel.width, mainpanel.height))         {             mainpanel.drawtobitmap(bitmap, new rectangle(3, 2, bounds.width, bounds.height));             bitmap.save(application.startuppath + "\\data\\programdata\\temppic.bmp");         }     } 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -