1

When i create a screenshot of the whole screen,
everything is on the screenshot, also the gui of my program.

Is there any way of achieving a screenshot of a clean desktop without
minimizing my form before and restoring after the screenshot?

Solution: seems like you have to make the window invisible and then minimize it. However if you set ShowInTaskbar to false just before you minimize it, it results in an awkward bug (see screenshot somewhere in the comments below)

  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Oct 12 '14 at 01:51
  • Changing the window visibility would be an issue? – BrunoLM Oct 12 '14 at 01:59
  • thx for changing the window title, i saw some older questions with tags in the title so i assumed it would be ok :) –  Oct 12 '14 at 12:28

1 Answers1

0

From your programs point of view the screen is simply an image, so if your form is there, "nothing" will be "behind" it. You must minimize or make your form invisible to achieve what you want.

As far as i know there is no OS that grants you access to its graphics pipeline and it would be a difficult task to get a "screenshot" exactly before your form is printed (considering you can grant your form is the last printed item in the screen).

Anyway, the way to go is this:

  • Minimize your form or make it invisible: "this.WindowState = FormWindowState.Minimized;" , "this.Visible=false;"
  • Hide it from the task bar "this.ShowInTaskbar = false;"
  • Take the screenshot with "CopyFromScreen".

Then maximize your form and make it appear again in the task bar.

SaintJob 2.0
  • 554
  • 4
  • 21
  • thanks, now it works. What i was missing was the windowstate = minimized. I thought when i just set its visibility to hide, its gone instantly, but on the screenshot its just half transparent in the normal windows 7 closing animation. –  Oct 12 '14 at 12:36
  • Sorry, it didn't work yet, i experience this but sometimes(!): http://pho.to/7Tt2Y When i sleep(10); then it works all fine again. Anyway, is there anything i can do so i dont need to sleep? –  Oct 12 '14 at 18:50
  • What is that grey rectangle? Is it the minimization animation or something? Is it your form? – SaintJob 2.0 Oct 12 '14 at 19:09
  • the grey rectangle is probably the minimize animation. It pops up for some split seconds when i dont use the sleep to wait till its gone. –  Oct 12 '14 at 19:42
  • I know that maybe you need your program to be shown in the task bar but, if you set ShowInTaskBar to false does the rectangle still apear? Apart, maybe the animation is cancelled if you set the parameter to false just before making the screenshot. – SaintJob 2.0 Oct 12 '14 at 19:48
  • hmm, awkward. Now the bug is gone though i didnt change any sourcecode o.O Lets see how this develops –  Oct 12 '14 at 20:18