如何通过编程获取C#异常的ScreenShots [英] How to take ScreenShots of C# Exceptions through Programming

查看:69
本文介绍了如何通过编程获取C#异常的ScreenShots的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何通过编程进行截屏,但是我想对运行时出现的异常屏幕截屏进行截屏吗?有可能吗?请给我建议...在此先感谢

位图位图=新位图(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height);

图形graphics = Graphics.FromImage(位图为Image);

graphics.CopyFromScreen(0,0,0,0,bitmap.Size);

bitmap.Save("c:\\ screenshot.jpeg",ImageFormat.Jpeg);.

I know how to take a Screen Shots through Programing but i want to take ScreenShots of the Exceptions Screen appear runtime? Is it possible to do? please Suggest me...Thanks in Advance

Bitmap bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);

Graphics graphics = Graphics.FromImage(bitmap as Image);

graphics.CopyFromScreen(0, 0, 0, 0, bitmap.Size);

bitmap.Save("c:\\screenshot.jpeg", ImageFormat.Jpeg);.

推荐答案

它可能会起作用-但您不能放它进入您的应用程序!这是一个例外-如果您看到此消息,则意味着您的程序无法处理该问题,并且实际上已崩溃.因此,您的应用程序的任何部分都无法进行屏幕截图.您可以将其放在单独的免费UI应用程序中,然后将其固定到Windows中的热键序列.

顺便说一句:请勿尝试写入启动驱动器的根目录-在Vista或更高版本的大多数情况下,它将无法正常工作,因为您需要管理员权限才能写入该文件夹.使用我的文档"或允许用户设置文件夹-一个另存为"对话框将是一个好主意.
It will probably work - but you can''t put it into your application! It''s an exception - and if you are seeing the message, that means that your program has failed to handle the problem, and has effectively crashed. So no part of your application is going to work to take the screen shot. You could put it in a separate UI free application and pin that to a hot key sequence in Windows though.

BTW: Don''t try to write to the root of the boot drive - it won''t work in most cases on Vista and above because you need admin privileges to write to that folder. Use My documents or allow the user to set the folder - a "Save as" dialog would be a good idea.


这篇关于如何通过编程获取C#异常的ScreenShots的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆