TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

<< Back to C-SHARP

C# TabControl: Windows Forms

Use the TabControl in Windows Forms to organize controls. Call SelectTab.
TabControl presents a tabbed layout in the user interface. The .NET Framework provides this versatile and easy-to-use control. We add the control, change its pages, manipulate it in C# code, and change its visual settings.
Start. To begin, you will need to create a new Windows Forms application in Visual Studio. Then, you can add the TabControl by opening the Toolbox pane and double-clicking on the TabControl icon.

Next: Right-click on the TabControl and select Properties. This will present you with the Properties dialog.

Properties: You can use this dialog to adjust many important visual settings and also the TabPages themselves.

TabPages. Adjusting the TabPages in the TabControl is important. This mechanism allows you to add a variable number of pages to your tab control. If your application is complex, you might need ten tab pages. If it is simple, you might only need two.

Tip: Please remember that users might get frustrated with complicated user interfaces.

Above, you can see the TabPage Collection Editor. To add an additional tab, please click the Add button. To remove a tab, select it and click Remove. You can change the background color of tabs, the font color, and many other things.

Tip: You should leave these alone unless your application's goal is to cause headaches.

Typically: It is smartest to use the default user interface colors for most applications.

Change tabs. How can you manipulate the TabControl using the C# language? First, if you want to do something in code when the user interacts somehow with the TabControl, try clicking on the lightning bolt icon and finding the appropriate event.

SelectTab: Another thing you can do, as we see here, is programmatically change the selected tab.

Tip: This code can restore a tab to the one that was open when the application last closed. It can focus a tab on start up.

C# program that uses SelectTab and SelectedIndex using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); // After initialize, select the second tab. tabControl1.SelectTab("tabPage2"); // This is another way to select the second tab. // ... You don't need both ways! tabControl1.SelectedIndex = 1; } } }
Appearance. There are more tricks to the TabControl in the Windows Forms Framework. One nice feature the TabControl has is the ability to change the appearance of the tabs to buttons or flat buttons.
For some kinds of applications, particularly those where for some reason the tab metaphor is not effective, try using the Buttons or FlatButtons enumerated constants for the Appearance property. Here, we see the FlatButtons appearance.
Please remember that the tabbed interface metaphor is thought to be very effective for many applications. In books such as Don't Make Me Think, by Steve Krug, this metaphor is shown to be much easier for users to interact with.

However: When you get too many tabs, the metaphor breaks down and it might be better to start using buttons for the appearance.

Summary. The TabControl in the .NET Framework and Windows Forms is a powerful and easy-to-use layout control. It can help you keep clutter in the finished window to a minimum, while not restricting the range of options you offer.
© TheDeveloperBlog.com
The Dev Codes

Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf