程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> C#截屏,

C#截屏,

編輯:C#入門知識

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

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved