c#实现截图功能

2009年3月8日星期日

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.IO;
using System.Runtime.InteropServices;
using System.Xml;
using System.Threading;

namespace jietu
{

public partial class Form1 : Form
{
[DllImport("User32.dll", EntryPoint = "FindWindow")]
private static extern IntPtr FindWindow(string lpClassName,
string lpWindowName);

[DllImport("user32.dll")]
public static extern void SetForegroundWindow(IntPtr hwnd);

IntPtr ParenthWnd;
public Form1()
{
InitializeComponent();
ParenthWnd = new IntPtr(0);
}

private void button1_Click(object sender, EventArgs e)
{
ParenthWnd = FindWindow(null, "所要截取窗口名称");

SetForegroundWindow(ParenthWnd);//让其置前

Image img = new Bitmap(Screen.AllScreens[0].Bounds.Width, Screen.AllScreens[0].Bounds.Height);
Graphics g = Graphics.FromImage(img);
g.CopyFromScreen(new Point(0, 0), new Point(0, 0), Screen.AllScreens[0].Bounds.Size);
screen body = new screen();
body.BackgroundImage = img;
body.Show();


}
}
}

0 评论:

发表评论