Develop a program that runs in the background in .NET?

后端 未结 6 1722
天涯浪人
天涯浪人 2020-12-04 08:53

I have made a small program in C# that I want to run in the background and it should only appear when a certain key combination is pressed. How can I do this?

6条回答
  •  难免孤独
    2020-12-04 09:05

    To allow the program to be completely invisible is, in my opinion, a bad idea. Because the user cannot interact with the program. I would recommend placing it in the SysTray (an icon by the clock in Windows)

        trayIcon      = new NotifyIcon();
        trayIcon.Text = "My application";
        trayIcon.Icon = TheIcon
    
        // Add menu to the tray icon and show it.
        trayIcon.ContextMenu = trayMenu;
        trayIcon.Visible     = true;
    
        Visible       = false; // Hide form window.
        ShowInTaskbar = false; // Remove from taskbar.
    

    To monitor keyboard you can use LowLevel Keyboard hook ( see example ) or attach a hootkey (See example)

提交回复
热议问题