感谢您使用微软的产品。您可以通过这样的方法实现对当前窗口的打印,首先将当前窗口的图像用截屏的方法复制到clipboard,然后在PrintPage方法中将clipboard中的图片打印出来:下面的范例通过点击button来调用打印事件。首先在类中定义一个System.Drawing.Printing.PrintDocument对象,在button1_click方法中调用SendKeys.Send("%{PRTSC}"),相当于您同时按alt+printscreen键,将当前窗口的图像复制到clipboard,然后调用System.Drawing.Printing.PrintDocument对象的print方法,进行打印。然后在PrintPage方法中将clipboard中的图像打印出来。private System.Drawing.Printing.PrintDocument printDocument1;
private void button1_Click(object sender, System.EventArgs e)
{
SendKeys.Send("%{PRTSC}");
Application.DoEvents();//Processes all Windows messages currently in the message queue
this.printDocument1.Print();
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
IDataObject iData = Clipboard.GetDataObject ();
Image img = (Image)iData.GetData (DataFormats.Bitmap);
e.Graphics.DrawImage(img,0,0);
}- 微软全球技术中心 开发技术支持本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款
(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
为了为您创建更好的讨论环境,请参加我们的用户满意度调查
(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。