2011-03-30 84 views
0

我試圖攔截關閉窗口,但它似乎失敗並關閉窗體應用程序。從本質上講,這個程序應該等待用戶在簽名板上的輸入,當有人開始簽名時它會彈出,但我需要阻止程序關閉。C#隱藏窗口而不是關閉

這裏是我試過,似乎沒有

private void Form1_FormClosing(object sender, FormClosingEventArgs e) 
{ 
    //reset hardware 
    e.Cancel = true; 
    sigPlusNET1.LCDRefresh(0, 0, 0, 240, 64); 
    sigPlusNET1.LCDSetWindow(0, 0, 240, 64); 
    sigPlusNET1.SetSigWindow(1, 0, 0, 240, 64); 
    sigPlusNET1.KeyPadClearHotSpotList(); 
    sigPlusNET1.SetLCDCaptureMode(1); 
    sigPlusNET1.SetTabletState(0); 
    this.Hide(); 

} 

什麼想法?

編輯:使用此代碼,應用程序正常關閉並且不會隱藏。

下面是工作得很好部分:

// Ok Button 
private void cmdClose_Click(object sender, EventArgs e) 
{ 
    //cmdSaveImage_Click(sender, e); 
    this.Visible = false; 
    sigPlusNET1.KeyPadClearHotSpotList(); 
    sigPlusNET1.ClearTablet(); 
    sigPlusNET1.KeyPadAddHotSpot(0, 1, 0, 0, 1000, 1000); 
    progTimer.Enabled = true; 
} 
+0

它究竟如何失敗?無論如何應用程序都關閉了嗎? – 2011-03-30 18:29:09

+0

@Justin Niessner是的,表單剛剛關閉,似乎忽略了它。 – Jeff 2011-03-30 18:30:33

+0

只是要知道:隱藏你的意思是最小化...我是對的? – digEmAll 2011-03-30 18:31:47

回答

3

確保在表單屬性中指定Form1_FormClosing作爲FormClosing事件的處理程序。

或者,您可以覆蓋實際的方法本身。

protected override void OnClosing(CancelEventArgs e) 
    { 
     e.Cancel = true; 
     base.OnClosing(e); 
    } 
+0

工作正常! protected override void OnClosing(CancelEventArgs e) e.Cancel = true; this.visable = false; (e); } – Jeff 2011-03-30 18:37:07

0

的問題可能是你hide the window
也許它會工作,如果你只是將其最小化。

+0

我在其他地方隱藏窗口,完全沒有任何問題。 – Jeff 2011-03-30 18:32:44

+0

只要它沒有關閉,隱藏表單也可以。 – Karsten 2011-03-30 18:39:49