GetTabPageOfComponent Method

TabPage.GetTabPageOfComponent Method

Retrieves the tab page that contains the specified object.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public static TabPage GetTabPageOfComponent(
	Object comp


Type: System.Object
The object to look for.

Return Value

Type: System.Windows.Forms.TabPage
The TabPage that contains the specified object, or null if the object cannot be found.

The following code example creates a TabControl with two TabPage objects, each containing one Button component. The parameter button2 is passed to the GetTabPageOfComponent method, which retrieves the TabPage containing button2. To verify that the correct tab page is retrieved, the SelectedIndex property sets the TabPage containing button2 to the currently selected tab page.

Use the System.Drawing and System.Windows.Forms namespaces for this example.

using System.Drawing;
using System.Windows.Forms;

public class Form1 : System.Windows.Forms.Form
	private TabControl tabControl1;
	private TabPage tabPage1;
	private TabPage tabPage2;
	private Button button1;
	private Button button2;

	private void InitializeMyTabs()
		tabControl1 = new System.Windows.Forms.TabControl();
		tabPage1 = new System.Windows.Forms.TabPage();
		tabPage2 = new System.Windows.Forms.TabPage();
		button1 = new System.Windows.Forms.Button();
		button2 = new System.Windows.Forms.Button();

		tabControl1.Controls.AddRange(new System.Windows.Forms.Control[] {
		tabControl1.Location = new System.Drawing.Point(40, 24);
		tabControl1.Size = new System.Drawing.Size(216, 216);
		tabControl1.TabIndex = 0;

		tabPage1.Controls.AddRange(new System.Windows.Forms.Control[] {button1});
		tabPage1.TabIndex = 0;
		tabPage2.Controls.AddRange(new System.Windows.Forms.Control[] {button2});
		tabPage2.TabIndex = 1;

		button1.Location = new System.Drawing.Point(64, 72);
		button2.Location = new System.Drawing.Point(64, 72);
		button2.Text = "button2";

		ClientSize = new System.Drawing.Size(292, 273);
		Controls.AddRange(new System.Windows.Forms.Control[] {tabControl1});

		// Gets the index of the TabPage containing button2.
		// Selects the index of the TabPage containing button2. 
		tabControl1.SelectedIndex = (TabPage.GetTabPageOfComponent(button2)).TabIndex;

	public Form1()

	static void Main() 
		Application.Run(new Form1());

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

© 2016 Microsoft