在 C# 中创建气球工具提示

发布于 2024-11-14 13:13:21 字数 262 浏览 2 评论 0原文

我可以知道如何在用 C# 编码的应用程序中制作弹出气泡消息吗?

例如,当我启动我的应用程序时,它会弹出“欢迎使用 UbuntuSE 应用程序”。

是的,弹出窗口不是消息框弹出窗口,而是托盘菜单中的弹出窗口。

与此类似的内容:

在此处输入图像描述

PS, 如果我没记错的话,这就是所谓的气球工具提示。但我如何在我的代码中使用它。

Can i know how can i make a popup bubble message in my application coded in C#.

Like example, when i start my application, it'll popup saying "Welcome to UbuntuSE App".

And yea, The popup is not the message box popup, it's the popup in the traymenu.

Something similar to this:

enter image description here

PS,
If i'm not wrong, this is called Balloon Tooltips. But how can i use this in my codes.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

惟欲睡 2024-11-21 13:13:21

如果您使用的是 Winform,则具有 NotifyIcon 类。该对象有一个 ShowBalloonTip 方法,它将显示气球提示:

var icon = new NotifyIcon();
icon.ShowBalloonTip(1000, "Balloon title", "Balloon text", ToolTipIcon.None)

If you're using Winforms you have the NotifyIcon class. This object has a ShowBalloonTip method which will show a balloon tip:

var icon = new NotifyIcon();
icon.ShowBalloonTip(1000, "Balloon title", "Balloon text", ToolTipIcon.None)
俏︾媚 2024-11-21 13:13:21

您一定正在寻找通知图标控件

在此处输入图像描述
另一个 CodeProject 示例

这是 MSDN 中的完整示例

you must be looking for the Notify Icon Control

enter image description here
another CodeProject Example

here is a full example in MSDN

抹茶夏天i‖ 2024-11-21 13:13:21

您可以使用 NotifyIcon< /a> 属于 .NET 2.0 System.Windows.Forms 一部分的控件。

检查:使用 NotifyIcon 控件

从 msdn,

NotifyIcon :指定创建通知的组件
通知区域中的图标。这
类不能被继承。

You can use the NotifyIcon control that's part of .NET 2.0 System.Windows.Forms.

Check : Using the NotifyIcon control

From the msdn,

NotifyIcon : Specifies a component that creates an
icon in the notification area. This
class cannot be inherited.

玩心态 2024-11-21 13:13:21

您必须设置属性“图标”,否则它不会弹出

    NotifyIcon ballon = new NotifyIcon();
    ballon.Icon = SystemIcons.Application;//or any icon you like
    ballon.ShowBalloonTip(1000, "Balloon title", "Balloon text", ToolTipIcon.None)

You have to set the property "icon" or it won't pop up

    NotifyIcon ballon = new NotifyIcon();
    ballon.Icon = SystemIcons.Application;//or any icon you like
    ballon.ShowBalloonTip(1000, "Balloon title", "Balloon text", ToolTipIcon.None)
眼泪淡了忧伤 2024-11-21 13:13:21
using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Windows.Forms;

namespace ShowToolTip
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btBallonToolTip_Click(object sender, EventArgs e)
        {
            ShowBalloonTip();
            this.Hide();
        }

        private void ShowBalloonTip()
        {
            Container bpcomponents = new Container();
            ContextMenu contextMenu1 = new ContextMenu();

            MenuItem runMenu = new MenuItem();
            runMenu.Index = 1;
            runMenu.Text = "Run...";
            runMenu.Click += new EventHandler(runMenu_Click);

            MenuItem breakMenu = new MenuItem();
            breakMenu.Index = 2;
            breakMenu.Text = "-------------";

            MenuItem exitMenu = new MenuItem();
            exitMenu.Index = 3;
            exitMenu.Text = "E&xit";

            exitMenu.Click += new EventHandler(exitMenu_Click);

            // Initialize contextMenu1
            contextMenu1.MenuItems.AddRange(
                        new System.Windows.Forms.MenuItem[] { runMenu, breakMenu, exitMenu });

            // Initialize menuItem1

            this.ClientSize = new System.Drawing.Size(0, 0);
            this.Text = "Ballon Tootip Example";

            // Create the NotifyIcon.
            NotifyIcon notifyIcon = new NotifyIcon(bpcomponents);

            // The Icon property sets the icon that will appear
            // in the systray for this application.
            string iconPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\setup-icon.ico";
            notifyIcon.Icon = new Icon(iconPath);

            // The ContextMenu property sets the menu that will
            // appear when the systray icon is right clicked.
            notifyIcon.ContextMenu = contextMenu1;

            notifyIcon.Visible = true;

            // The Text property sets the text that will be displayed,
            // in a tooltip, when the mouse hovers over the systray icon.
            notifyIcon.Text = "Morgan Tech Space BallonTip Running...";
            notifyIcon.BalloonTipText = "Morgan Tech Space BallonTip Running...";
            notifyIcon.BalloonTipTitle = "Morgan Tech Space";
            notifyIcon.ShowBalloonTip(1000);
        }

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

        void runMenu_Click(object sender, EventArgs e)
        {
            MessageBox.Show("BallonTip is Running....");
        }
    }
}
using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Windows.Forms;

namespace ShowToolTip
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btBallonToolTip_Click(object sender, EventArgs e)
        {
            ShowBalloonTip();
            this.Hide();
        }

        private void ShowBalloonTip()
        {
            Container bpcomponents = new Container();
            ContextMenu contextMenu1 = new ContextMenu();

            MenuItem runMenu = new MenuItem();
            runMenu.Index = 1;
            runMenu.Text = "Run...";
            runMenu.Click += new EventHandler(runMenu_Click);

            MenuItem breakMenu = new MenuItem();
            breakMenu.Index = 2;
            breakMenu.Text = "-------------";

            MenuItem exitMenu = new MenuItem();
            exitMenu.Index = 3;
            exitMenu.Text = "E&xit";

            exitMenu.Click += new EventHandler(exitMenu_Click);

            // Initialize contextMenu1
            contextMenu1.MenuItems.AddRange(
                        new System.Windows.Forms.MenuItem[] { runMenu, breakMenu, exitMenu });

            // Initialize menuItem1

            this.ClientSize = new System.Drawing.Size(0, 0);
            this.Text = "Ballon Tootip Example";

            // Create the NotifyIcon.
            NotifyIcon notifyIcon = new NotifyIcon(bpcomponents);

            // The Icon property sets the icon that will appear
            // in the systray for this application.
            string iconPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\setup-icon.ico";
            notifyIcon.Icon = new Icon(iconPath);

            // The ContextMenu property sets the menu that will
            // appear when the systray icon is right clicked.
            notifyIcon.ContextMenu = contextMenu1;

            notifyIcon.Visible = true;

            // The Text property sets the text that will be displayed,
            // in a tooltip, when the mouse hovers over the systray icon.
            notifyIcon.Text = "Morgan Tech Space BallonTip Running...";
            notifyIcon.BalloonTipText = "Morgan Tech Space BallonTip Running...";
            notifyIcon.BalloonTipTitle = "Morgan Tech Space";
            notifyIcon.ShowBalloonTip(1000);
        }

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

        void runMenu_Click(object sender, EventArgs e)
        {
            MessageBox.Show("BallonTip is Running....");
        }
    }
}
不爱素颜 2024-11-21 13:13:21

感谢您的信息!
做了这样的东西并且成功了!

    private void NotifyBaloon(string text, string tooltip, string title, bool show)
    {
        notifyIconMain.Text = text;
        notifyIconMain.BalloonTipText = tooltip;
        notifyIconMain.BalloonTipTitle = title;
        if (show)
            notifyIconMain.ShowBalloonTip(1000);
    }

Thanks for the info!
Made something like this and worked!

    private void NotifyBaloon(string text, string tooltip, string title, bool show)
    {
        notifyIconMain.Text = text;
        notifyIconMain.BalloonTipText = tooltip;
        notifyIconMain.BalloonTipTitle = title;
        if (show)
            notifyIconMain.ShowBalloonTip(1000);
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文