C#截屏_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > C#截屏

C#截屏

 2016/6/20 5:30:29  roucheng  程序员俱乐部  我要评论(0)
  • 摘要:本实例代码实现了WinForm截屏保存为图片,亲测可行。界面截图:下载:http://hovertree.com/h/bjaf/scjyuanma.htm以下代码可以实际运行,在项目HoverTreeCSJ中运行成功。/*何问起http://hovertree.com/hovertreescj/*/usingSystem;usingSystem.Drawing;usingSystem.Drawing.Imaging;usingSystem.IO;usingSystem.Windows
  • 标签:C#

本实例代码实现了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#复习⑤
发表评论
用户名: 匿名