Take screenshot of screen behind form?

ⅰ亾dé卋堺 提交于 2019-12-13 01:15:47

问题


I am trying to take a screenshot with a form of a screen BUT I don't want my form to be included in the screenshot. This is my current Code for getting the screenshot.

Bitmap bt;
Graphics screenshot;
private void button1_Click_1(object sender, EventArgs e)
{
    this.Opacity = 0;
    bt = new Bitmap(Screen.FromControl(this).Bounds.Width, Screen.FromControl(this).Bounds.Height, PixelFormat.Format32bppArgb);
    screenshot = Graphics.FromImage(bt);
    screenshot.CopyFromScreen(Screen.FromControl(this).Bounds.X, Screen.FromControl(this).Bounds.Y, 0, 0, Screen.FromControl(this).Bounds.Size, CopyPixelOperation.SourceCopy);
    pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
    pictureBox1.Image = bt;
    this.Opacity = 1;
}

This works to a degree, but the problem is that when I do this it causes the screen to flicker each time. Is there any way to make it so it doesn't include my form, but still takes everything behind it?


回答1:


You cannot take a screenshot of what is behind your form, but you can hide you form, take a screen shot and show your form again. How to do this:

  1. Hide your form
  2. Wait some time until the screen has been repainted.
  3. Take the screenshot.
  4. Show your form.

You should make 2 asynchronous by using a Timer class.

Good luck with your task.



来源:https://stackoverflow.com/questions/16740083/take-screenshot-of-screen-behind-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!