gpt4 book ai didi

c# - 运行无形式通知用户控件?

转载 作者:行者123 更新时间:2023-11-30 14:02:37 25 4
gpt4 key购买 nike

在我的代码中,我需要在不显示任何形式的情况下运行通知控件,我该怎么做?我只是将此代码添加到 program.cs 主线程,但它不起作用请帮我解决这个问题?

        Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run();
TaskbarIcon tb = new TaskbarIcon();
var balloon = new Warning();
tb.ShowCustomBalloon(balloon, PopupAnimation.Fade, 12000);

警告是用户控件

最佳答案

我建议使用 ApplicationContext 实例作为参数调用 Application.Run():

class Kernel : ApplicationContext
{
private TaskbarIcon tb = new TaskbarIcon();

public void Show()
{
var ballon = new Warning();
tb.ShowCustomBalloon(balloon, PopupAnimation.Fade, 12000);
}

/// <summary>
/// Closes the application.
/// </summary>
public void Close()
{
Application.Exit();
}
}

程序.cs:

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

using(var kernel = new Kernel())
{
Application.Run(kernel);
}

这样它就可以与默认的 .NET NotifyIcon 一起工作。

关于c# - 运行无形式通知用户控件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5605577/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com