- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace FormCopy
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- //截屏幕方法
- private void FormCpy()
- {
- string sFileName = "";
- string sPath = @"E:/Test/Image/";
- Random rnd = new Random();
- int width = 0;
- int heigh = 0;
- width = this.Size.Width;
- heigh = this.Size.Height;
- Bitmap bmp = new Bitmap(width, heigh);
- System.Reflection.Assembly ass = System.Reflection.Assembly.GetExecutingAssembly();
- sFileName =sPath + DateTime.Now.ToString("yyyyMMddHHmmss_") + ass.GetName().Name + "_" + this.Name + "_" + rnd.Next(999) + ".jpg";
- this.DrawToBitmap(bmp, new Rectangle(0, 0, width, heigh));
- bmp.Save(sFileName,System.Drawing.Imaging.ImageFormat.Jpeg);
- }
- private void button1_Click(object sender, EventArgs e)
- {
- FormCpy();
- }
- }
- }
也可将第34行替换成
Clipboard.SetImage(bmp);//将图片保存到粘贴板,不保存实际文件。 然后在Word上直接粘贴