Any way to create a hidden main window in C#?

前端 未结 12 934
粉色の甜心
粉色の甜心 2020-12-25 13:02

I just want a c# application with a hidden main window that will process and respond to window messages.

I can create a form without showing it, and can then call Ap

12条回答
  •  被撕碎了的回忆
    2020-12-25 13:27

    Excellent! That link pointed me in the right direction. This seems to work:

            Form f = new Form1();
            f.FormBorderStyle = FormBorderStyle.FixedToolWindow;
            f.ShowInTaskbar = false;
            f.StartPosition = FormStartPosition.Manual;
            f.Location = new System.Drawing.Point(-2000, -2000);
            f.Size = new System.Drawing.Size(1, 1);
            Application.Run(f);
    

    To keep it from showing up in Alt-Tab, you need it to be a tool window. Unfortunately, this prevents it from starting minimized. But setting the start position to Manual and positioning it offscreen does the trick!

提交回复
热议问题