2016-10-26 3 views
0

나는 수량의 사전이 비어 있으면 사용자가 판매 탭에 들어 가지 않아야하는 Windows 양식 응용 프로그램을 만듭니다. 저는 메트로 디자인 및 재료 스킨 혼합을 사용하여 그것을 생성하고 있습니다. 최대하지만이 작품 일정한 형태의 컨트롤을 사용하지만, 지하철과 여기서 일하지 않는 재료를 사용하면 컨트롤의 탭 선택 이벤트를 처리 할 필요가 코드사람이 winfom의 탭 페이지로 들어가는 것을 방지하는 방법

//check if selected tab is sales tab 
      if (tcmain.SelectedTab == tpSales) 
      { 
       //check if our cart is empty or not 
       if (Globals.qty.Count == 0) 
       { 
        //show error msg 
        var diaEmptCart = MessageBox.Show("There Are 0 Products in Cart", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 
        //set selected tab as purchase 
        tcmain.SelectedTab = tpPurchase; 
       } 
       else 
       { 
        //or show the products available in cart for sales 
        //populate combo box with them 
        cmbPro.DataSource = new BindingSource(Globals.qty, null); 
        //set key as display member 
        cmbPro.DisplayMember = "Key"; 
       } 
      } 
      //check if selectedd tab is tab purchase 
      if (tcmain.SelectedTab == tpPurchase) 
      { 
       if (Globals.qty.Count == 0) 
       { 
        //if yes, setting cart empty 
        pbCart.Image = Image.FromFile(@"C:\Users\ThE PrOgRaMmEr\Documents\Visual Studio 2013\Projects\simpleInventory.cs.MUI\simpleInventory.cs\Resources\crt_empty.png"); 
       } 
       else 
       { 
        //if not, setting cart full 
        pbCart.Image = Image.FromFile(@"C:\Users\ThE PrOgRaMmEr\Documents\Visual Studio 2013\Projects\simpleInventory.cs.MUI\simpleInventory.cs\Resources\crt_full.png"); 
       } 
      } 
     } 

답변

0

의 작품이다. 이것을 시도하십시오 :

private void tcmain_Selecting(object sender, TabControlCancelEventArgs e) 
{ 
     //Change whatever you want 
     if (tcmain.TabPages[e.TabPageIndex] == tpSales && Globals.qty.Count == 0) 
      e.Cancel = true; 
} 

그러나 질문은 심지어 탭을 표시하는 이유입니다. 필요하지 않은 탭을 만들지 않는 것이 좋습니다.

+0

그런 다음 해당 솔루션이 작동하므로 private void tcmain_SelectedIndexChanged (Object sender, EventArgs e) 메서드를 제거해야합니다. – Lucifer

+0

사전을로드 할 때 탭 페이지를 사용하지 않도록 설정하고 비어있는 것이 좋습니다. 따라서 사용자는 Messagebox를 얻지 못합니다. Sales가 비어 있고 tpSales.Enable = false를 호출하면 데이터 검사를로드합니다. – Sebi

+0

@ Jaydeep, 선택한 탭에서 특정 작업을 수행하고 싶지 않다면이 이벤트를 제거 할 수 있습니다. 또한 그것이 유용한 경우 대답으로 표시하시기 바랍니다 –

관련 문제