简体   繁体   中英

C# Get a selected TabControl tab in Visual Studio WinForm

I'm looking for the method which returns a bool on whether or not a tab in a TabControl is selected. I would think there would be something like tabPage1.IsSelected() but there isn't. I found this: TabControl.SelectedTab Property However, this SelectedTab property is absent from my WinForms class for some reason. Not sure if it's been taken out or what. Thanks.

I tried below code to know which tab is selected.

  private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
  {        
     if (tabControl1.SelectedTab == tabControl1.TabPages["operationstabPage"])
     {
           //add your code here
     }
  }

To get the selected tab in tab control, you can use -

var selectedTab = this.tabControl1.SelectedTab;

So you can do -

bool tabSelected = this.tabControl1.SelectedTab == this.tabPage1;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM