Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hello guys... Its a REPOST. In my program, user will first need to enter the credentials on Tab1, in order to be able to see the rest of the tabs (and controls on it). If wrong credentials are given then upon clicking any other tab, for a fraction of second it shows the other tab (onwhich I click: say Tab3) then switches almost immediately back to first tab, although the code works fine . Here is what I have tried so far
C#
private void OnMouseDown(object sender, MouseEventArgs e) 
{
  if (e.Button == MouseButtons.Left)
  {
      if (tabMainTabCtrl.SelectedIndex != 0)
      {
        if (IsUserAuthenticated) // this is set when user is authenticated or not
          tabMainTabCtrl.SelectedIndex = m_iSelectedTab;
        else
          tabMainTabCtrl.SelectedIndex = 0;
      }
  }
}

private void tabMainTabCtrl_SelectedIndexChanged(object sender, EventArgs e)
{
     m_iSelectedTab = tabMainTabCtrl.SelectedIndex; //m_iSelectedTab: class level global variable
}

As I said, it works fine but it seems strange. So what can be a better solution? thnx for any input.
Posted

1 solution

Hello Overloaded_Name,

Delete the OnMouseDown method and change tabMainTabCtrl_SelectedIndexChanged method as below

C#
private void tabMainTabCtrl_SelectedIndexChanged(object sender, EventArgs e)
{
     if ( tabMainTabCtrl.SelectedIndex != 0)
     {
       if ( !IsUserAuthenticated )
       {
         MessageBox.Show("You are not authenticated user");
         tabMainTabCtrl.SelectedIndex = 0;
       }
     }
}


I thing this help you.
 
Share this answer
 
v2
Comments
AmbiguousName 3-May-12 3:14am    
Hi There. Thanks for your time. In my program if user is not authenticated and he clicks other tabs, then other tab shows up just for a fraction of second.

But In you solution, It literally takes me there and will stay there until I don't dismiss the message box. Tell you what, I tried the code in my 'OnMouseDown()' event in 'SelectedIndexChanged()' and the behavior remains the same as discussed in orginal post.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900