C# - 带有 GUI 的后台应用程序 [英] C# - Background application with GUI

查看:25
本文介绍了C# - 带有 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 项目,但传递 ApplicationContextApplication.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆