본문 바로가기

.NET/Winforms

[WINFORMS] Tab Control

Tab Control

  • Tab Control 은 Tab page 를 포함하고 있다.

선택된 Tab 화면 확인하는 방법

if (tabControl1.SelectedTab == tabControl1.TabPages["tab1"])
{ 
}

화면 전환, 설정

tabControl1.SelectedTab = tabPage2;

페이지 내부 비활성화

  • 텝 메뉴가 비활성화 되는 것이 아닌 내부 컨텐츠가 비활성화 된다.
 tabPage1.Enabled = false;

Tab 제거

tabControl1.TabPages.Remove(tabPage1);

Tab change event

private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
    // Get the currently selected tab index.
    int selectedIndex = tabControl1.SelectedIndex;

    // Perform actions based on the selected tab index.
    switch (selectedIndex)
    {
        case 0:
            // Code to handle the first tab.
            break;
        case 1:
            // Code to handle the second tab.
            break;
        // Add cases for other tabs as needed.
    }
}

Reference

 

TabControl Class (System.Windows.Forms)

Manages a related set of tab pages.

learn.microsoft.com