}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new CaptureScreenForm());
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint (e);
if(image != null)
{
this.picbox.Image = image;
}
else
{
this.picbox.Image = null;
this.picbox.Refresh();
}
}
// 引用API
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
public static extern bool BitBlt(
IntPtr hdcDest, //目标设备的句柄
int nXDest, // 目标对象的左上角的X坐标
int nYDest, // 目标对象的左上角的X坐标
int nWidth, // 目标对象的矩形的宽度
int nHeight, // 目标对象的矩形的长度
IntPtr hdcSrc, // 源设备的句柄
int nXSrc, // 源对象的左上角的X坐标
int nYSrc, // 源对象的左上角的X坐标
System.Int32 dwRop // 光栅的操作值
);
private void exitBtn_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
private void aboutBtn_Click(object sender, System.EventArgs e)
{
MessageBox.Show("Code by Star in 2006-3-17,E_mail: ygh_01@163.com ,thank you to use this.");
}
private void ClearBtn_Click(object sender, System.EventArgs e)
{
CaptureScreenForm.image = null;
this.Invalidate();
}
private void saveBtn_Click(object sender, System.EventArgs e)
{
bool isSave = true;
SaveFileDialog saveImageDialog = new SaveFileDialog();
saveImageDialog.Title = "Capture screen image save dialog";
saveImageDialog.Filter= @"jpeg|*.jpg|bmp|*.bmp|gif|*.gif";
if(saveImageDialog.ShowDialog() == DialogResult.OK)
{
string fileName = saveImageDialog.FileName.ToString();
if(fileName != "" && fileName != null)
{
string fileExtName = fileName.Substring(fileName.LastIndexOf(".") 1).ToString();
System.Drawing.Imaging.ImageFormat imgformat = null;
if(fileExtName!="")
{
switch(fileExtName)
{
case "jpg":
imgformat = System.Drawing.Imaging.ImageFormat.Jpeg;
break;
case "bmp":
imgformat = System.Drawing.Imaging.ImageFormat.Bmp;
break;
case "gif":
imgformat = System.Drawing.Imaging.ImageFormat.Gif;
break;
default:
MessageBox.Show("只能存取为: jpg,bmp,gif 格式");
isSave = false;
break;
}
}
//默认保存为JPG格式
if(imgformat == null)
{
评论加载中…
![]() |