如何确定单击了哪个Windows气球工具提示?

时间:2018-01-18 23:59:44

标签: c# .net windows winforms

我有一个C#应用程序,它使用NotifyIcon.ShowBalloonTip在Windows中显示几种不同类型的气球通知。如果用户点击它,我希望能够将操作与每个气球提示相关联。但是,NotifyIcon.BalloonTipClicked似乎没有提供用户实际点击的气球的任何指示。如何确定用户与之交互的气球提示?

以下是展示问题的简短示例:

var notifyIcon = new System.Windows.Forms.NotifyIcon
{
    Text = "testing notifications",
    Icon = System.Drawing.SystemIcons.Application,
    Visible = true
};

notifyIcon.BalloonTipClicked += (sender, args) =>
{
    Console.WriteLine($"User clicked a balloon, but which one? sender: {sender}, args: {args}");
};

for (var i = 0; i < 5; i++) {
    notifyIcon.ShowBalloonTip(30000, $"title {i}", $"text {i}", System.Windows.Forms.ToolTipIcon.Info);
}

0 个答案:

没有答案