The Tab Pages of a Tab Control |
|
As mentioned previously, a tab control is made of tabs. These are the actual objects that make up a tab control. A tab control can have one or more of them. If you create only a tab control in your application, it is useless and does not play its intended role. To make it useful, you must add property pages to it. |
To support property pages, the .NET Framework provides the TabPage class. Because the property pages completely depend on the tab control, the TabPage class is not represented in the Toolbox. If you want to add a tab page to a tab control, the TabControl class is equipped with a property named TabPages, which is of type TabPageCollection. TabPageCollection is a collection class that implements the IList, the ICollection, and the IEnumerable interfaces. If you create a tab control at design time by taking it from the Toolbox and adding it to a form, the tab control gets automatically equipped with two tabs. Here is an example:
At design time, to add a property page, you have various options:
If you create the tab pages at design time, like all other controls, the names of tab pages are cumulative. As you add them, the first would be named tabPage1, the second would be named tabPage2, etc. If you plan to programmatically refer to the tab pages, you should give each a more meaningful name. As done with any other control, to set the name of a property page, after selecting it, in the Properties window, change the value of the (Name) field. To programmatically create a property page, declare a variable of type TabPage, allocate memory for it using the new operator, and add it to the Controls collection of its eventual tab control. Here is an example: Imports System Imports System.Drawing Imports System.Windows.Forms Module Exercise Public Class WinControls Inherits Form Private tclPropertySheet As TabControl Private pgeController As TabPage Dim components As System.ComponentModel.Container Public Sub New() InitializeComponent() End Sub Public Sub InitializeComponent() Size = New Size(345, 228) StartPosition = FormStartPosition.CenterScreen tclPropertySheet = New TabControl() tclPropertySheet.Location = New Point(14, 16) tclPropertySheet.Size = New Size(310, 170) pgeController = New TabPage() tclPropertySheet.Controls.Add(pgeController) Controls.Add(tclPropertySheet) End Sub Public Shared Function Main() As Integer Application.Run(New WinControls()) Return 0 End Function End Class End Module This would produce:
Alternatively, you can declare a variable of type TabPage, allocate memory for it using the new operator, and add it to the TabPages collection of its tab control. Here is an example: Imports System Imports System.Drawing Imports System.Windows.Forms Module Exercise Public Class WinControls Inherits Form Private tclPropertySheet As TabControl Private pgeController As TabPage Private pgeAccount As TabPage Dim components As System.ComponentModel.Container Public Sub New() InitializeComponent() End Sub Public Sub InitializeComponent() Size = New Size(345, 228) StartPosition = FormStartPosition.CenterScreen tclPropertySheet = New TabControl() tclPropertySheet.Location = New Point(14, 16) tclPropertySheet.Size = New Size(310, 170) pgeController = New TabPage() tclPropertySheet.Controls.Add(pgeController) pgeAccount = New TabPage() tclPropertySheet.TabPages.Add(pgeAccount) Controls.Add(tclPropertySheet) End Sub Public Shared Function Main() As Integer Application.Run(New WinControls()) Return 0 End Function End Class End Module
If you have added a tab page by mistake or you don't want a particular page anymore, you can remove it. To remove a property page, first click its tab to select it. Then,
To programmatically delete a tab control, call the Remove() method of the TabPages property. |
|
||
Previous | Copyright © 2007-2011 FunctionX | Next |
|