C# - 带有 GUI 的后台应用程序 [英] C# - Background application with GUI
问题描述
我的问题是我想创建一个后台应用程序,但它的用户界面可以恢复并最小化到系统托盘,并且它从 Windows 开始.我尝试搜索如何开始,但我只找到了有关没有 UI 或创建表单并隐藏它的 Windows 服务的线程.所以我的问题是我应该如何开始?一个 Windows 窗体?一个服务并以某种方式添加一个接口?
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 tried searching how to start but I only found threads about Windows Service without UI or creating form and hiding it. So my question is how should I start ? A Windows Form ? A Service and add an interface somehow ?
谢谢!
推荐答案
这是一种创建不绑定到表单的应用程序的方法.使用标准 WinForms 项目,但传递 ApplicationContext 到 Application.Run()
:
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
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[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
}
}
这篇关于C# - 带有 GUI 的后台应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!