C# - Background application with GUI

前端 未结 2 1052
谎友^
谎友^ 2021-01-28 02:30

My problem is that I want to create a background application but with a user interface that could be restored and minimized to the system tray and it starts with windows. I trie

2条回答
  •  清酒与你
    2021-01-28 02:57

    Here's a way to create an app that isn't tied to a Form. Use a Standard WinForms Project, but pass your custom implementation of ApplicationContext to Application.Run():

    static class Program
    {
        /// 
        /// The main entry point for the application.
        /// 
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MyContext());
        }
    
    }
    
    public class MyContext : ApplicationContext
    {
    
        public MyContext()
        {
            // this is the new "entry point" for your application
    
            // use Application.Exit() to shut down the application
    
            // you can still create and display a NotifyIcon control via code for display in the tray
            // (the icon for the NotifyIcon can be an embedded resource)
            // you can also display forms as usual when necessary
        }
    
    }
    

提交回复
热议问题