.NET 2.0的WinForm打印屏幕 [英] .NET 2.0 WinForm print screen
本文介绍了.NET 2.0的WinForm打印屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要打印对话框的图像,就好像[ALT] [打印SCRN]被使用。该框架是否允许这种以编程方式完成?
I would like to print an image of a dialog, as if [alt][Print Scrn] were used. Does the framework allow for this to be done programmatically?
推荐答案
的的 Graphics.CopyFromScreen(..)的方法应该做你所需要的。
The Graphics.CopyFromScreen(..) method should do what you need.
下面是一个很好的示例中,我发现在网络上:
Here's a good sample I found on the web:
http://www.geekpedia.com/tutorial181_Capturing-screenshots-使用-Csharp.html
编辑: code样品:(我创建它作为一个扩展方法)
Code sample: (I created it as an extension method)
public static class FormExtensions
{
public static void SaveAsImage(this Form form, string fileName, ImageFormat format)
{
var image = new Bitmap(form.Width, form.Height);
using (Graphics g = Graphics.FromImage(image))
{
g.CopyFromScreen(form.Location, new Point(0, 0), form.Size);
}
image.Save(fileName, format);
}
}
可以使用:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
this.SaveAsImage("foo.bmp", ImageFormat.Bmp);
}
}
这篇关于.NET 2.0的WinForm打印屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文