2016-02-05 72 views
-2
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函數,但它也沒有工作。 有什麼幫助嗎?在通知中顯示新表單

+0

你能澄清「沒有工作」嗎?你有沒有得到一個錯誤,或者什麼都沒有?您是否放置了一箇中斷點並查看該事件中的代碼是否正在執行?您似乎已將一些設計器代碼與上面代碼片段中的代碼隱藏代碼混合在一起......這些代碼不會按原樣編譯。 –

+0

Sendingmail sm = new Sendingmail(); sm.Show(); //這就是我所做的,沒有發生任何事情,窗體沒有打開 –

+0

嘗試sm.ShowDialog(); – NickGames

回答

2

您是否在上面聲明瞭sm變量? 嘗試在mousedoubleClick中的sm.Show();之前聲明表單sm變量。

+0

sm值是我在類中頂部聲明的新形式的名稱 –

+1

啊好吧,我認爲是這樣..你能粘貼其餘的代碼嗎?也許這樣我們可以更好地幫助你。通常在使用Ashok Patel的代碼時它必須工作。 – NickGames

+0

public partial class Mainmenu:表格 { Sendingmail sm = new Sendingmail(); //這是寫在beginnig,然後我們有通知代碼,然後在上面顯示的名爲MouseDoubleClick的事件 –

0

雙擊你應該寫如下代碼。

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

//確保您創建SM表單的新對象。

+0

它沒有工作的工作。 –

+0

顯示整個代碼 –

+0

你是否得到任何異常或任何東西?是否在點擊時調用該通知事件? –

0

在button6_Click函數底部添加下面的代碼。

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