在notificationclick上显示新表单

时间:2016-02-05 05:53:25

标签: c# visual-studio notifications

enter code here


 namespace WindowsFormsApplication1
{
public partial class Mainmenu : Form
{
    Sendingmail sm = new Sendingmail();

    public Mainmenu()
    {
        InitializeComponent();

    }
 private void button6_Click(object sender, EventArgs e)
    {




        this.WindowState = FormWindowState.Normal;
        notifyIcon1.Icon = SystemIcons.Exclamation;
        notifyIcon1.BalloonTipIcon = ToolTipIcon.Info;
        notifyIcon1.BalloonTipTitle = "Patient medicine";
        notifyIcon1.BalloonTipText = "Please be noted that a patient should take his medicine now" +
                                    Environment.NewLine +
                                    "click on the icon when medicine given";

        notifyIcon1.ShowBalloonTip(20000);
        notifyIcon1.Visible = true;

    }

    private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
    {

       Sendingmail sm = new Sendingmail();
        sm.Show();

    }

会显示一个通知,当我点击显示的通知时,我想要打开一个表单,我尝试了如上所示的mouseDoubleClick功能,但它也没有用。 有什么帮助吗?

3 个答案:

答案 0 :(得分:2)

您是否在上面声明了sm变量? 尝试在mousedoubleclick中的sm.Show();之前声明表单sm变量。

答案 1 :(得分:0)

双击,你应该编写如下代码。

private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e) 
{
     Form2 sm = new Form2();
     sm.Show();
}

//确保您创建SM表单的新对象。

答案 2 :(得分:0)

在底部的button6_Click函数中添加以下代码。

 notifyIcon1.Click += (sender, e) =>
 {
   Sendingmail sm = new Sendingmail();
    sm.Show();
 };