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

前端 未结 12 932
粉色の甜心
粉色の甜心 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:20

    public partial class Form1 : Form
    {
        private bool _isApplicationRun;
    
        public Form1(bool applicationRun)
        {
            InitializeComponent();
            _isApplicationRun = applicationRun;
        }
    
        protected override void SetVisibleCore(bool value)
        {
            if (_isApplicationRun)
            {
                _isApplicationRun = false;
    
                base.SetVisibleCore(false);
                return;
            }
    
            base.SetVisibleCore(value);
        }
    }
    
    static class Program
    {
    
        [STAThread]
        static void Main()
        {
    
            Application.Run(new Form1(true));
        }
    }
    

提交回复
热议问题