码迷,mamicode.com
首页 > Windows程序 > 详细

C#截屏

时间:2016-06-20 06:45:59      阅读:362      评论:0      收藏:0      [点我收藏+]

标签:

本实例代码实现了WinForm截屏保存为图片,亲测可行。

界面截图:
技术分享

下载:http://hovertree.com/h/bjaf/scjyuanma.htm


以下代码可以实际运行,在项目HoverTreeCSJ中运行成功。

/* 何问起 http://hovertree.com/hovertreescj/ */
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Windows.Forms;

namespace HoverTreeSCJ.SCJForms.ToolForms
{
    public partial class Form_GetScreen : Form
    {
        public Form_GetScreen()
        {
            InitializeComponent();
        }

        private void button_getScreen_Click(object sender, EventArgs e)
        {
            FormWindowState h_currentState = MdiParent.WindowState;
            if (checkBox_isHide.Checked)
            {
                //MdiParent.Hide();
                //http://hovertree.com/h/bjaf/de7qg5wd.htm
                this.MdiParent.WindowState = FormWindowState.Minimized;
            }

            //创建图象,保存将来截取的图象
            Bitmap image = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
            Graphics imgGraphics = Graphics.FromImage(image);
            //设置截屏区域 柯乐义
            imgGraphics.CopyFromScreen(0, 0, 0, 0, new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height));
            //保存
            SaveImage(image);

            if (checkBox_isHide.Checked)
            {
                this.MdiParent.WindowState = h_currentState;
               // this.MdiParent.Show();
            }
        }


        //保存图象文件
        private void SaveImage(Image image)
        {
            //http://hovertree.com/h/bjaf/ruwwcg2p.htm
            saveFileDialog_getScreen.FileName = "何问起截图" + DateTime.Now.ToFileTime();
            if (saveFileDialog_getScreen.ShowDialog(this) == DialogResult.OK)
            {
               
                string fileName = saveFileDialog_getScreen.FileName;
                string extension = Path.GetExtension(fileName);
                if (extension == ".jpg")
                {
                    image.Save(fileName, ImageFormat.Jpeg);
                }
                else
                {
                    image.Save(fileName, ImageFormat.Bmp);
                }
            }
        }
    }
}

转自:http://hovertree.com/h/bjaf/76q5yeli.htm

推荐:http://www.cnblogs.com/roucheng/p/DataGridView.html

http://hovertree.top

C#截屏

标签:

原文地址:http://www.cnblogs.com/roucheng/p/csjieping.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!