本實例代碼實現了WinForm截屏保存為圖片,親測可行。界面截圖:下載:http://hovertree.com/h/bjaf/scjyuanma.htm以下代碼可以實際運行,在項目HoverTreeCSJ中運行成功。 轉自:http://hovertree.com/h/bjaf/76q5yeli. ...
本實例代碼實現了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