I want to create a simple programm that takes a screenshot and saves it without showing a window.
Which type of Element do I have to use?-
- a normal Windows-Form app and I have to hide the window
- a console application
- something else?
I want to create a simple programm that takes a screenshot and saves it without showing a window.
Which type of Element do I have to use?-
Here's even simpler solution.
This way you don't have to hide any windows because you don't create any.
Use right tool for the job.
Create empty project or class library. Add new class (if you use class library template it will be generated already).
Add static method with name Main
.
public class Class1
{
public static void Main()
{
// do your staff
}
}
After you build a project .exe file will be generated which you can use.
No needs for workaround steps with hiding windows.
You can use both. I particularly prefer to work with winform. just hide the window:
this.WindowState = FormWindowState.Minimized;
then:
Rectangle bounds = this.Bounds;
using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
{
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(new Point(bounds.Left,bounds.Top), Point.Empty, bounds.Size);
}
bitmap.Save("C://test.jpg", ImageFormat.Jpeg);
}