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:\Temp\printscreen.jpg", ImageFormat.Jpeg);
This is my code for print screen button. The problem is that I press the button few times and it just write over the old image file (printscreen.jpg), it will not create another new image file such as printscreen1.jpg.
Pressing PRINT SCREEN captures an image of your entire screen and copies it to the Clipboard in your computer's memory. You can then paste (CTRL+V) the image into a document, email message, or other file.
Alt + PrtSc – Save a screenshot of the current window to Pictures. Ctrl + PrtSc – Copy the screenshot of the entire screen to the clipboard. Shift + Ctrl + PrtSc – Copy the screenshot of a specific region to the clipboard.
Depending on your hardware, you may use the Windows Logo Key + PrtScn button as a shortcut for print screen. If your device does not have the PrtScn button, you may use FnFnKeys with an Fn key or F Lock provide two sets of commands for many keys. This includes the top row of standard function keys (F1–F12). Standard commands are labeled on the front of the keys (such as F3). Alternate commands are labeled on top of the keys (such as Redo).https://support.microsoft.com › en-us › topicHow do I use the Fn key/F Lock key/Alternate command keys? + Windows logo key + Space Bar to take a screenshot, which can then be printed.
Try this. It will generate a unique file each time.
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:\Temp\printscreen"+Guid.NewGuid()+".jpg", ImageFormat.Jpeg);
OR
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);
var date = DateTime.Now.ToString("MMddyyHmmss");
bitmap.Save(@"C:\Temp\printscreen"+date+".jpg", ImageFormat.Jpeg);
it will not create another new image file
You are not asking it to create one, your code
bitmap.Save(@"C:\Temp\printscreen.jpg", ImageFormat.Jpeg);
is always writing to the same file.
new image file such as printscreen1.jpg
If you want to create a new file, you need to generate your filename dynamically. Something like
string fileName = System.IO.Path.GetTempPath() + DateTime.Now.ToString() + ".jpg";
bitmap.Save(fileName, ImageFormat.Jpeg);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With