如何在Windows 10的系统托盘中显示经典的BalloonTip,而不是C#中的Toast通知?

问题描述 投票:0回答:1

我正在为Windows构建一个Windows Forms应用程序,基于.Net 4.7.2框架。该应用程序旨在工作在Windows 10加上Windows Server 2019系统上。

当用户最小化应用程序和应用程序进入托盘时,我想显示一个 经典的 BalloonTip在它的托盘图标上面,像这样。

enter image description here

问题是,当我这样做的时候,

    private void form1_Resize(object sender, EventArgs e)
    {

        if (this.WindowState == FormWindowState.Minimized)
        {
            this.Hide();
            trayIcon.Visible = true;
            trayIcon.ShowBalloonTip(8000);
        }

    }

我的 "BalloonTip "在我现在工作的Windows10系统中是这样显示的。

enter image description here

我知道这是Windows10的新风格。我也了解了Windows组策略和它的注册表设置。我不想改变Windows的策略。

编辑:另外,烤面包通知只出现2-3秒,而不是我设置的8秒......。

我如何在C#中实现这个功能?

c# winforms system-tray balloon-tip
1个回答
0
投票

也许,Tulpep.NotificationWindow nuget包可以为你工作。

Pls有一个看在这个链接: Foxlearn Notification

EDIT:

创建你自己的表单来定制气球通知,并使用下面的代码。

请注意,button1是一个小按钮在右上角的'X'和关闭的意思。

接下来,添加一个图片框到你的表格中,大小,以便填写表格,并添加下面的图片到图片框中。enter image description here

然后,你可以按照你想要的方式设计通知,添加标签,图片框等。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BubbleNotificationTest
{
    public partial class Form1 : Form
    {
        Timer t = new Timer();
        Timer fadeIn = new Timer();
        Timer fade = new Timer();
        public Form1()
        {
            InitializeComponent();
            Opacity = 0;
            fadeIn.Interval = 100;
            this.BackColor = Color.FromArgb(28, 28, 28);
            this.TransparencyKey = Color.FromArgb(28, 28, 28);
            this.StartPosition = FormStartPosition.Manual;
            this.Location = new Point(Screen.FromControl(this).Bounds.X + 850, Screen.FromControl(this).Bounds.Y + 662);
            fadeIn.Tick += new EventHandler(fadeIn_Tick);
            fadeIn.Start();
            t.Tick += new EventHandler(t_Tick);
            fade.Tick += new EventHandler(fade_Tick);
            fade.Interval = 100;
            t.Interval = 6000;
            t.Start();
        }

        private void fadeIn_Tick(object sender, EventArgs e)
        {
            this.Opacity += 0.05;
            if (this.Opacity == 1)
            {
                fadeIn.Stop();
            }
        }

        private void t_Tick(object sender, EventArgs e)
        {
            fade.Start();
        }

        private void fade_Tick(object sender, EventArgs e)
        {
            this.Opacity -= 0.05;
            if (this.Opacity == 0)
            {
                fade.Stop();
                this.Close();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}

这里是结果。enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.