【问题标题】:System tray message alert when result > 0结果 > 0 时系统托盘消息警报
【发布时间】:2014-04-15 08:24:43
【问题描述】:

有一个功能,用户可以互相发送消息并将其数据保存到表中。我在检查来自数据库的新消息下面写了那个简单的代码:

lDataParameter.Add("msg", _msgEnd);

ultragrid1.DataSource = _msgEnd.Tables[0];

if (ultragrid1.Rows.Count > 0)
{
    ultragrid1.Rows[0].Selected = true;

    MessageBox.Show("You have" + ultragrid1.Rows.Count.ToString() + " 1 new message"); 
}

有效!现在我想在系统托盘上显示那个消息框,但是应用程序关闭了......

如何让我的应用进入系统托盘?

【问题讨论】:

标签: c# windows winforms system-tray


【解决方案1】:

谢谢各位。我做到了。

 public Form1()
        {

            InitializeComponent();

            this.components = new System.ComponentModel.Container();
            this.contextMenu1 = new System.Windows.Forms.ContextMenu();
            this.menuItem1 = new System.Windows.Forms.MenuItem();

            // Initialize contextMenu1 
            this.contextMenu1.MenuItems.AddRange(
                        new System.Windows.Forms.MenuItem[] { this.menuItem1 });

            // Initialize menuItem1 
            this.menuItem1.Index = 0;
            this.menuItem1.Text = "E&xit";
            this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);

            // Set up how the form should be displayed. 
            this.ClientSize = new System.Drawing.Size(292, 266);
            this.Text = "Notify Icon Example";

            // Create the NotifyIcon. 
            this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);

            // The Icon property sets the icon that will appear 
            // in the systray for this application.
            notifyIcon1.Icon = new Icon("Icon.ico");

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

            // The Text property sets the text that will be displayed, 
            // in a tooltip, when the mouse hovers over the systray icon.
            notifyIcon1.Text = "Form1 (NotifyIcon example)";
            notifyIcon1.Visible = true;

            // Handle the DoubleClick event to activate the form.
            notifyIcon1.DoubleClick += new System.EventHandler(this.notifyIcon1_DoubleClick);

        }

现在我想创建更多菜单。

menuItem1.Index = 1; this.menuItem1.Text = "我&nfo";

如何用它来创作?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-16
    • 1970-01-01
    相关资源
    最近更新 更多