当前位置: 移动技术网 > IT编程>开发语言>c# > C#实现屏幕拷贝的方法

C#实现屏幕拷贝的方法

2019年07月18日  | 移动技术网IT编程  | 我要评论

本文实例讲述了c#实现屏幕拷贝的方法。分享给大家供大家参考。具体如下:

方法一:

using system;
using system.collections.generic;
using system.componentmodel;
using system.data;
using system.drawing;
using system.text;
using system.windows.forms;
using system.drawing.drawing2d;
namespace windowsapplication2
{
  public partial class form21 : form
  {
    public form21()
    {
      initializecomponent();
    }
    private void button1_click(object sender, eventargs e)
    {
      rectangle screenrect = screen.primaryscreen.workingarea;
      bitmap dumpbitmap = new bitmap(screenrect.width, screenrect.height);
      graphics tg = graphics.fromimage(dumpbitmap);
      tg.copyfromscreen(0, 0, 0, 0, new size(dumpbitmap.width, dumpbitmap.height));
      this.picturebox1.backgroundimage = dumpbitmap;
      this.picturebox1.backgroundimagelayout = imagelayout.stretch;
      dumpbitmap.save(@"c:/image1.bmp");
    }
  }
}

方法二:

using system;
using system.collections.generic;
using system.componentmodel;
using system.data;
using system.drawing;
using system.text;
using system.windows.forms;
namespace windowsapplication2
{
  public partial class form22 : form
  {
    public form22()
    {
      initializecomponent();
    }
    private void button1_click(object sender, eventargs e)
    {
      rectangle rect = new rectangle(0, 0, this.size.width, this.size.height);
      bitmap dumpbitmap = new bitmap(this.size.width, this.size.height);
      this.drawtobitmap(dumpbitmap, rect);
      this.picturebox1.backgroundimage = dumpbitmap;
      this.picturebox1.backgroundimagelayout = imagelayout.stretch;
      dumpbitmap.save(@"c:/image2.bmp");
    }
  }
}

希望本文所述对大家的c#程序设计有所帮助。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网