/// <summary> ///Auxiliary Classes/// </summary> Public classScreenhelper {//File Save Private Static string_filepath =string. Empty; #regionconstructor function/// <summary> ///Private Constructors/// </summary> PrivateScreenhelper () {}/// <summary> ///Static Constructors/// </summary> StaticScreenhelper () {_filepath=System.Environment.CurrentDirectory; stringFilePath = system.configuration.configurationmanager.appsettings["Screenshotfilepath"]; if(!string. IsNullOrEmpty (FilePath)) {_filepath=FilePath; } } /// <summary> /// /// </summary> /// <param name= "FileName" >file name, not including suffix</param> /// <param name= "FilePath" >file path</param> Public Static stringScreenshot (stringFileName,stringFilePath) { Try { stringdtstring = DateTime.Now.ToString ("YYYY-MM-DD"); stringdir = FilePath +"\\Screenshot\\"+ dtstring +"\\"; //determines whether the folder exists, does not exist, and creates if(System.IO.Directory.Exists (dir) = =false) {System.IO.Directory.CreateDirectory (dir); } stringFullPath = dir + fileName +"_"+ Guid.NewGuid (). ToString () +". jpg"; //get the current screen resolutionScreen SCR =Screen.primaryscreen; Rectangle RC=SCR. Bounds; intIwidth =RC. Width; intIheight =RC. Height; //Create a bitmap that is as big as the screenImage myimage =NewBitmap (iwidth, iheight); //Create a Graphics object from an object that inherits from the image classGraphics g =graphics.fromimage (myimage); //grab the screen and copy it to the myimage.G.copyfromscreen (NewPoint (0,0),NewPoint (0,0),NewSize (iwidth, iheight)); //Save As FileMyimage.save (FullPath); returnFullPath; } Catch(Exception ex) {Com.LogHelper.WriteLog (ex). Message, ex. StackTrace, Com.LogType.OtherError); return string. Empty; } } /// <summary> /// /// </summary> /// <param name= "FileName" >file name, not with suffix name</param> Public Static stringScreenshot (stringfileName) { returnscreenshot (FileName, _filepath); } #endregion }
C # screenshot