C# tabpage active『Check if a specific tab page is selected (active)』
C# tabpage active『Check if a specific tab page is selected (active)』
資料來源:
01.https://stackoverflow.com/questions/8653036/check-if-a-specific-tab-page-is-selected-active/39185625
02.自己開發的專案
Code
方案01.
private void tab1_SelectedIndexChanged(object sender, EventArgs e) { if (tab1.SelectedTab == tab1.TabPages["tabname"])//your specific tabname { // your stuff } }
方案02.
this.m_tabMain.SelectedIndexChanged += new System.EventHandler(this.m_tabMain_SelectedIndexChanged); private void m_tabMain_SelectedIndexChanged(object sender, EventArgs e)//工作區改變時也同時改變左側選單 { m_TPOld = m_tabMain.SelectedTab;//--2017/02/22 製作返回按鈕功能 TabPage_Push();//m_StackTPOld.Push(m_TPOld);//--2017/02/22 製作返回按鈕功能 //--- //Outlook子按鈕點擊後,保持顏色識別 m_intOutlookClickMainIndex = -1; m_intOutlookClickSubIndex = -1; //---Outlook子按鈕點擊後,保持顏色識別 if(m_blnBookmarkHide==true) { return; } //--- //裝置管理子頁選擇連動Outlook選單切換 if (m_tabMain.SelectedTab == m_tabV09device) { m_intOutlookClickMainIndex = m_intMenuPosition2Var[0]; m_intOutlookClickSubIndex = 0; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[0]; } if (m_tabMain.SelectedTab == m_tabSub0000) { m_intOutlookClickMainIndex = m_intMenuPosition2Var[0]; m_intOutlookClickSubIndex = 1; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[0]; } if ((m_tabMain.SelectedTab == m_tabSub000001) || (m_tabMain.SelectedTab == m_tabSub000002)) { m_intOutlookClickMainIndex = m_intMenuPosition2Var[0]; m_intOutlookClickSubIndex = 1; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[0]; } if (m_tabMain.SelectedTab == m_tabSub0001) { m_intOutlookClickMainIndex = m_intMenuPosition2Var[0]; m_intOutlookClickSubIndex = 2; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[0]; } if (m_tabMain.SelectedTab == m_tabSub000100) { m_intOutlookClickMainIndex = m_intMenuPosition2Var[0]; m_intOutlookClickSubIndex = 2; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[0]; } if (m_tabMain.SelectedTab == m_tabSub0002) { m_intOutlookClickMainIndex = m_intMenuPosition2Var[0]; m_intOutlookClickSubIndex = 3; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[0]; } if (m_tabMain.SelectedTab == m_tabSub000200) { m_intOutlookClickMainIndex = m_intMenuPosition2Var[0]; m_intOutlookClickSubIndex = 3; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[0]; } if (m_tabMain.SelectedTab == m_tabSub0003) { m_intOutlookClickMainIndex = m_intMenuPosition2Var[0]; m_intOutlookClickSubIndex = 4; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[0]; } if (m_tabMain.SelectedTab == m_tabSub000301) { m_intOutlookClickMainIndex = m_intMenuPosition2Var[0]; m_intOutlookClickSubIndex = 4; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[0]; } //--- //新增m_tabV09device頁籤元件變數並建立對應初始化 - 把m_tabSub0004的顯示程式碼替換成m_tabV09device /* if (m_tabMain.SelectedTab == m_tabSub0004) { m_intOutlookClickMainIndex = 0; m_intOutlookClickSubIndex = 4; m_OutlookBar1.SelectedBand = 0; } if (m_tabMain.SelectedTab == m_tabSub000400) { m_intOutlookClickMainIndex = 0; m_intOutlookClickSubIndex = 4; m_OutlookBar1.SelectedBand = 0; } */ //---新增m_tabV09device頁籤元件變數並建立對應初始化 - 把m_tabSub0004的顯示程式碼替換成m_tabV09device //---裝置管理子頁選擇連動Outlook選單切換 //--- //人員卡片管理子頁選擇連動Outlook選單切換 if (m_tabMain.SelectedTab == m_tabSub0100) { m_intOutlookClickMainIndex = m_intMenuPosition2Var[1]; m_intOutlookClickSubIndex = 1; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[1]; } if (m_tabMain.SelectedTab == m_tabSub010000) { m_intOutlookClickMainIndex = m_intMenuPosition2Var[1]; m_intOutlookClickSubIndex = 1; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[1]; } if (m_tabMain.SelectedTab == m_tabSub0101) { m_intOutlookClickMainIndex = m_intMenuPosition2Var[1]; m_intOutlookClickSubIndex = 3; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[1]; } if (m_tabMain.SelectedTab == m_tabSub010100) { m_intOutlookClickMainIndex = m_intMenuPosition2Var[1]; m_intOutlookClickSubIndex = 3; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[1]; } if (m_tabMain.SelectedTab == m_tabSub0102) { m_intOutlookClickMainIndex = m_intMenuPosition2Var[1]; m_intOutlookClickSubIndex = 2; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[1]; } if (m_tabMain.SelectedTab == m_tabSub010200) { m_intOutlookClickMainIndex = m_intMenuPosition2Var[1]; m_intOutlookClickSubIndex = 2; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[1]; } if (m_tabMain.SelectedTab == m_tabSub0103) { m_intOutlookClickMainIndex = m_intMenuPosition2Var[1]; m_intOutlookClickSubIndex = 0; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[1]; } if (m_tabMain.SelectedTab == m_tabSub0104) { m_intOutlookClickMainIndex = m_intMenuPosition2Var[1]; m_intOutlookClickSubIndex = 4; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[1]; } if (m_tabMain.SelectedTab == m_tabSub010400) { m_intOutlookClickMainIndex = m_intMenuPosition2Var[1]; m_intOutlookClickSubIndex = 4; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[1]; } //---人員卡片管理子頁選擇連動Outlook選單切換 //--- //門區通行授權子頁選擇連動Outlook選單切換 if (m_tabMain.SelectedTab == m_tabSub0200) { m_intOutlookClickMainIndex = m_intMenuPosition2Var[2]; m_intOutlookClickSubIndex = 0; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[2]; } if (m_tabMain.SelectedTab == m_tabSub020000) { m_intOutlookClickMainIndex = m_intMenuPosition2Var[2]; m_intOutlookClickSubIndex = 0; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[2]; } if (m_tabMain.SelectedTab == m_tabSub0201) { m_intOutlookClickMainIndex = m_intMenuPosition2Var[2]; m_intOutlookClickSubIndex = 4; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[2]; } if (m_tabMain.SelectedTab == m_tabSub0202) { m_intOutlookClickMainIndex = m_intMenuPosition2Var[2]; m_intOutlookClickSubIndex = 3; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[2]; } if (m_tabMain.SelectedTab == m_tabSub0203) { m_intOutlookClickMainIndex = m_intMenuPosition2Var[2]; m_intOutlookClickSubIndex = 1; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[2]; } if (m_tabMain.SelectedTab == m_tabSub0204) { m_intOutlookClickMainIndex = m_intMenuPosition2Var[2]; m_intOutlookClickSubIndex = 1; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[2]; } if (m_tabMain.SelectedTab == m_tabSub0205) { m_intOutlookClickMainIndex = m_intMenuPosition2Var[2]; m_intOutlookClickSubIndex = 2; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[2]; } if (m_tabMain.SelectedTab == m_tabSub020300) { m_intOutlookClickMainIndex = m_intMenuPosition2Var[2]; m_intOutlookClickSubIndex = 1; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[2]; } //---門區通行授權子頁選擇連動Outlook選單切換 //--- //報表作業子頁選擇連動Outlook選單切換 if (m_tabMain.SelectedTab == m_tabSub0300) { m_intOutlookClickMainIndex = m_intMenuPosition2Var[3]; m_intOutlookClickSubIndex = 0; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[3]; } if (m_tabMain.SelectedTab == m_tabSub0301) { m_intOutlookClickMainIndex = m_intMenuPosition2Var[3]; m_intOutlookClickSubIndex = 0; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[3]; } if (m_tabMain.SelectedTab == m_tabSub0302)//新增三個OUTLOOK報表下子按鈕的子頁選擇連動Outlook選單切換 { m_intOutlookClickMainIndex = m_intMenuPosition2Var[3]; m_intOutlookClickSubIndex = 1; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[3]; } if (m_tabMain.SelectedTab == m_tabSub0303)//新增三個OUTLOOK報表下子按鈕的子頁選擇連動Outlook選單切換 { m_intOutlookClickMainIndex = m_intMenuPosition2Var[3]; m_intOutlookClickSubIndex = 2; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[3]; } if (m_tabMain.SelectedTab == m_tabSub0304)//新增三個OUTLOOK報表下子按鈕的子頁選擇連動Outlook選單切換 { m_intOutlookClickMainIndex = m_intMenuPosition2Var[3]; m_intOutlookClickSubIndex = 3; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[3]; } //---報表作業子頁選擇連動Outlook選單切換 if (m_tabMain.SelectedTab == m_tabSub0305)//新增三個OUTLOOK報表下子按鈕的子頁選擇連動Outlook選單切換 { m_intOutlookClickMainIndex = m_intMenuPosition2Var[3]; m_intOutlookClickSubIndex = 4; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[3]; } //--- //指紋管理子頁選擇連動Outlook選單切換 if (m_tabMain.SelectedTab == m_tabSub0400) { m_intOutlookClickMainIndex = m_intMenuPosition2Var[4]; m_intOutlookClickSubIndex = 0; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[4]; } //---指紋管理子頁選擇連動Outlook選單切換 //--- //修正系統頁子頁選擇連動Outlook選單切換修正BUG if (m_tabMain.SelectedTab == m_tabSys) { m_intOutlookClickMainIndex = m_intMenuPosition2Var[5]; m_intOutlookClickSubIndex = 0; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[5]; } //---修正系統頁子頁選擇連動Outlook選單切換修正BUG //--- //製作權限管理畫面 ~ 製作獨立對應頁籤元件+頁籤預設初始化 if (m_tabMain.SelectedTab == m_tabSub0502) { m_intOutlookClickMainIndex = m_intMenuPosition2Var[5]; m_intOutlookClickSubIndex = 2; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[5]; } if (m_tabMain.SelectedTab == m_tabSub0501) { m_intOutlookClickMainIndex = m_intMenuPosition2Var[5]; m_intOutlookClickSubIndex = 1; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[5]; } //---製作權限管理畫面 ~ 製作獨立對應頁籤元件+頁籤預設初始化 //--- //建立即時狀態實體UI頁籤-子頁選擇連動Outlook選單切換 if (m_tabMain.SelectedTab == m_tabSub0600) { m_intOutlookClickMainIndex = m_intMenuPosition2Var[6]; m_intOutlookClickSubIndex = 0; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[6]; } //---建立即時狀態實體UI頁籤-子頁選擇連動Outlook選單切換 //--- //建立RFID實體UI頁籤-子頁選擇連動Outlook選單切換 if (m_tabMain.SelectedTab == m_tabSub0602) { m_intOutlookClickMainIndex = m_intMenuPosition2Var[6]; m_intOutlookClickSubIndex = 1; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[6]; } //---建立RFID實體UI頁籤-子頁選擇連動Outlook選單切換 //--- //建立遠端開門實體UI頁籤-子頁選擇連動Outlook選單切換 if (m_tabMain.SelectedTab == m_tabSub0601) { m_intOutlookClickMainIndex = m_intMenuPosition2Var[6]; m_intOutlookClickSubIndex = 2; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[6]; } //---建立遠端開門實體UI頁籤-子頁選擇連動Outlook選單切換 //--- //建立門區列表UI頁籤-子頁選擇連動Outlook選單切換 if (m_tabMain.SelectedTab == m_tabSub0603) { m_intOutlookClickMainIndex = m_intMenuPosition2Var[6]; m_intOutlookClickSubIndex = 3; m_OutlookBar1.SelectedBand = m_intMenuPosition2Var[6]; } //---建立門區列表UI頁籤-子頁選擇連動Outlook選單切換 }