문제

First time posting on this forum, and also very new to coding. Sorry if this is an easy question but I'm doing all sorts of things wrong.

The situation I want to save a screenshot, and I want to filename to be the current date like:

string path = DateTime.Now.ToShortDateString().ToString();

And I'm trying this:

ScreenCapture s = new ScreenCapture();
s.CaptureWindowToFile(this.Handle,(@"C:\images\" + path + ".png"), ImageFormat.Png);

which is a mess, and doesn't work. Any help would be appreciated even if you tell me to first learn more and then start with my own projects.

EDIT: The screencapture class I used: http://www.developerfusion.com/code/4630/capture-a-screen-shot/

도움이 되었습니까?

해결책

You probably have invalid characters in your time string. Use:

DateTime.Now.ToString("ddMMyyHHmmss");

You can change the order as you like. The order I wrote is "day, month, year, hour, minute, second"

다른 팁

you could declare your variable using the examples below

var path = DateTime.Now.ToString("ddMMyyHHmmss");

or

 string path = DateTime.Now.ToString("ddMMyyHHmmss");
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top