3

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?
quetzalcoatl
  • 32,194
  • 8
  • 68
  • 107
Regster Up
  • 113
  • 1
  • 2
  • 7
  • 1
    you can start with either project type. both will create valid windows applications. easier will be a forms app: you can just not create and show the form in `Main()`, and replace the code in Main() with the screen capture. – Cee McSharpface Mar 28 '17 at 18:47

3 Answers3

3

Here's even simpler solution.

  1. Create a console application.
  2. Open the Properties on the generated project
  3. Go to the Application tab
  4. Change the Output type to Windows Application

This way you don't have to hide any windows because you don't create any.

3

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.

Fabio
  • 31,528
  • 4
  • 33
  • 72
1

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);
 }
Paulo
  • 577
  • 3
  • 8
  • 23
  • 2
    Yup, hiding "winforms" window is much easier than hiding "console" window. However, what you wrote will actually only **minimize** the window, not hide it. For real hiding, see http://stackoverflow.com/questions/70272/single-form-hide-on-startup FYI: as I said, you can also hide the console window, for that see http://stackoverflow.com/questions/3571627/show-hide-the-console-window-of-a-c-sharp-console-application – quetzalcoatl Mar 28 '17 at 18:52