What type of project in Visual Studio should I use to create a "hidden" utility?

I want to create a simple program that takes a screenshot and saves it without showing the window.

What type of item should I use?

  • normal Windows-Form application and I need to hide the window
  • console application
  • something else?
+3


source to share


3 answers


Here's an even simpler solution.

  • Create a console application.
  • Open Properties in the generated project
  • Go to the Application tab
  • Change the Output Type to Windows Application


This way you don't need to hide any windows, because you are not creating them.

+3


source


Use the right tool for the job.

Create an empty project or class library. Add a new class (if you are using a class library template it will be generated already). Add a static method named Main

.



public class Class1
{
     public static void Main()
     {
          // do your staff
      }
}

      

Once the project is created, an .exe file will be generated that you can use.
No need for workarounds with hidden windows.

+3


source


You can use both. I especially prefer working 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);
 }

      

+1


source







All Articles