}
}
}
private void fullScreenBtn_Click(object sender, System.EventArgs e)
{
CaptureScreenForm.image = windowFullScreen();
picbox.Image = CaptureScreenForm.image;
}
public static Bitmap windowFullScreen()
{
//建立屏幕Graphics
Graphics grpScreen = Graphics.FromHwnd(IntPtr.Zero);
//根据屏幕大小建立位图
Bitmap bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height,grpScreen);
//建立位图相关Graphics
Graphics grpBitmap = Graphics.FromImage(bitmap);
//建立屏幕上下文
IntPtr hdcScreen = grpScreen.GetHdc();
//建立位图上下文
IntPtr hdcBitmap = grpBitmap.GetHdc();
//将屏幕捕捉保存在图位中
BitBlt(hdcBitmap,0,0,bitmap.Width,bitmap.Height,hdcScreen,0,0,0x00CC0020);
//关闭位图句柄
grpBitmap.ReleaseHdc(hdcBitmap);
//关闭屏幕句柄
grpScreen.ReleaseHdc(hdcScreen);
//释放位图对像
grpBitmap.Dispose();
//释放屏幕对像
grpScreen.Dispose();
//返回捕捉位图
return bitmap;
}
private void mouseCaptureBtn_Click(object sender, System.EventArgs e)
{
MouseCaptureForm mouseCapture = new MouseCaptureForm();
mouseCapture.Show();
}
}
}
另一个截屏文件:
MouseCaptureForm.cs
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace CaptureScreen
{
/// <summary>
/// MouseCaptureForm 的摘要说明。
/// </summary>
public class MouseCaptureForm : System.Windows.Forms.Form
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
//
//自定义变量
//
private Point pot;
private Rectangle area = Rectangle.Empty;
private Image img;
private int index = -1;
private string noselectString = "\n.请按下鼠标左键不放拖动选取截图区域\n\n .单击鼠标右键或按ESC取消截图";
private string selectingString = "\n.松开鼠标左键确定选取范围\n\n.按ESC重新选择";
private string selectedString = "\n.按鼠标左键调整选择范围\n\n .双击鼠标左键保存截图 \n\n.按鼠标右键重新选择 \n\n.ESC键取消截图";
private System.Windows.Forms.Label tiptext;
//
//系统生成定义
//
private System.ComponentModel.Container components = null;
public MouseCaptureForm()
评论加载中…
![]() |