Change accept button with tabs

前端 未结 3 1385
伪装坚强ぢ
伪装坚强ぢ 2021-01-06 12:59

I have a windows form application written in C# and it has three tabs and I would like the accept button change with the active tab. Like When I am in tab 1 I want button _

3条回答
  •  轮回少年
    2021-01-06 13:34

    You can do different things based on the tab that is currently selected by using the following code in the AcceptButton_Click event handler:

    if (tabControl1.SelectedTab == tabPage1)
    {
        //Do something
    }
    else if (tabControl1.SelectedTab == tabPage2)
    {
        //Do something different
    }
    

    If you prefer to work with strings, each tab page has a unique name:

    switch (tabControl1.SelectedTab.Name)
    {
        case "Tab1Name":
            //Do something
            break;
        case "Tab2Name":
            //Do something different
            break;
    }
    

    If this answered your question, please mark it as the answer to your question.

提交回复
热议问题