-1

I'm trying to work out some code for a tabControl in my program. I want the program to hide a specific button if the main tabIndex = 0 (the main tab). In the event, a new tab is open or selected it will display the button. When the user closes a specific tab, it will check if returned to the main tab the hide the button. Below is what i have coded. So far, it only works if i call it on form load.

 if (this.tabControl1.SelectedIndex == 0)
        {
            btCloseReport.Visible = false;
        }

        else
        btCloseReport.Visible = true;

Thanks

Dv

DV2022
  • 11
  • 3
  • 1
    I'm just guessing, but maybe you need to add your hiding button logic, into tabControlIndexChange event. In that way, you will get the current index, every time you change it. – Jasc24 Feb 28 '20 at 22:37
  • Thanks Jasc24 you were correct. I added a TabControl.SelectedIndexChanged Event and its not working perfectly. – DV2022 Feb 28 '20 at 22:53
  • you're welcome @David – Jasc24 Feb 28 '20 at 23:25

1 Answers1

1

Ok, i follow Jasc24's advice and added a TabControl.SelectedIndexChanged Event

private void TabControl1_SelectedIndexChanged(Object sender, EventArgs e) {

 if (this.tabControl1.SelectedIndex == 0)
        {
            btCloseReport.Visible = false;
        }

        else
        btCloseReport.Visible = true;}

Link here for more info: https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.tabcontrol.selectedindexchanged?view=netframework-4.8

DV2022
  • 11
  • 3