C# 创建像 Windows Messenger 或 AVG 这样的弹出气球

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/413656/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 02:27:45  来源:igfitidea点击:

Creating a Popup Balloon like Windows Messenger or AVG

c#.netpopup-balloons

提问by Malfist

How can I create a Popup balloon like you would see from Windows Messenger or AVG or Norton or whomever?

我如何创建一个弹出气球,就像您在 Windows Messenger、AVG、Norton 或其他任何人中看到的那样?

I want it to show the information, and then slide away after a few seconds.

我希望它显示信息,然后在几秒钟后滑开。

Edit: It needs to be blocking like Form.ShowDialog()because the program exits after displaying the notification

编辑:它需要像 Form.ShowDialog() 一样阻塞,因为程序在显示通知后退出

采纳答案by BFree

You can use the notifyIcon control that's part of .NET 2.0 System.Windows.Forms. That allows you to place an icon for your application in the System Tray. Then, you can call the ShowBalloonTip(int timeOut) method on that. Be sure however to first set the text, and icon properties on the notifyIcon for it to work. Small code sample:

您可以使用属于 .NET 2.0 System.Windows.Forms 的 notifyIcon 控件。这允许您在系统托盘中为您的应用程序放置一个图标。然后,您可以调用 ShowBalloonTip(int timeOut) 方法。但是,请确保首先在 notifyIcon 上设置文本和图标属性以使其工作。小代码示例:

private void button1_Click(object sender, EventArgs e)
        {
            this.notifyIcon1.BalloonTipText = "Whatever";
            this.notifyIcon1.BalloonTipTitle = "Title";
            this.notifyIcon1.Icon = new Icon("icon.ico");
            this.notifyIcon1.Visible = true;
            this.notifyIcon1.ShowBalloonTip(3);
        }

EDIT: Ok, so notifyIcon won't work for you. My second suggestion would then be to create your own control for this. Actually, I would use a form. A simple form, with no borders, and no control box and just have a timer running so you can set the Opacity for fade in/out. Then, you can easily get the bottom right of the screen using the Rectangle Screen.PrimaryScreen.WorkingArea. Then just show your form at that position.

编辑:好的,notifyIcon 对你不起作用。我的第二个建议是为此创建您自己的控件。实际上,我会使用表格。一个简单的表单,没有边框,没有控制框,只有一个正在运行的计时器,因此您可以设置淡入/淡出的不透明度。然后,您可以使用 Rectangle Screen.PrimaryScreen.WorkingArea 轻松获得屏幕的右下角。然后在那个位置展示你的表格。

回答by rravuri

You might want to look at this article http://www.codeproject.com/KB/miscctrl/RobMisNotifyWindow.aspxwhich has code to display an MSN Messenger-like notification window

您可能想查看这篇文章http://www.codeproject.com/KB/miscctrl/RobMisNotifyWindow.aspx,其中包含显示类似 MSN Messenger 的通知窗口的代码

回答by jwmiller5

The .NET 1.1 Visual Basic Power Packhad a toaster control.

.NET 1.1 Visual Basic Power Pack有一个烤面包机控件。

回答by Shog9

Don't create a modal (blocking) balloon. Please. A big part of the design of these UIs is that they are notdialogs: they're transient, potentially non-interactiveelements, intended to provide incidental information to a user withoutnecessarily interrupting their workflow. A balloon that steals focus and blocks user input would be irritating at best - if you needa dialog, then use a dialog.

不要创建模态(阻塞)气球。请。这些 UI 设计的很大一部分是它们不是对话框:它们是暂时的、潜在的非交互式元素,旨在向用户提供附带信息不必中断他们的工作流程。窃取焦点并阻止用户输入的气球充其量只会令人恼火 - 如果您需要对话框,请使用对话框。