2011-06-26 40 views
-6

我試過了所有我能想到的東西,但看上去沒有任何工作。當用戶單擊我的選項卡控件的第三個選項卡頁面時,如果他們確定要轉到該選項卡頁面,我想要一個messageBox出現。任何幫助?如何在顯示選項卡頁時顯示MessageBox?

+2

WinForms? WPF?其他? –

+0

@Jeff Mercado它的WinForms。 – SRH

+0

在選擇事件運行時,您無法防止選中選項卡。避免用消息框向用戶發送垃圾郵件,我很少不回答「是的,該死!」在一個無用的'你是zure'的信息。 –

回答

6

處理Selecting事件。在索引更改之前它會被觸發,因此如果您決定這樣做,您可以取消更改。

private void myTabControl_Selecting(object sender, TabControlCancelEventArgs e) 
{ 
    if (e.TabPageIndex == 2) 
    { // the third page is being selected 
     var result = MessageBox.Show(
         "Change to tab?", 
         "Change?", 
         MessageBoxButtons.YesNo, 
         MessageBoxIcon.Question, 
         MessageBoxDefaultButton.Button2); 
     if (result == DialogResult.No) 
      e.Cancel = true; // cancel it if the user said No 
    } 
}