Freigeben über


TabControl.TabCount-Eigenschaft

Ruft die Anzahl der Registerkarten in der Registerleiste ab.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

Syntax

'Declaration
Public ReadOnly Property TabCount As Integer
'Usage
Dim instance As TabControl
Dim value As Integer

value = instance.TabCount
public int TabCount { get; }
public:
property int TabCount {
    int get ();
}
/** @property */
public int get_TabCount ()
public function get TabCount () : int

Eigenschaftenwert

Die Anzahl der Registerkarten in der Registerleiste.

Beispiel

Im folgenden Codebeispiel wird ein TabControl mit fünf TabPage-Objekten erstellt. In diesem Beispiel wird die TabCount-Eigenschaft verwendet, um zu ermitteln, wie viele Registerkarten die Registerleiste von tabControl1 aktuell enthält.

Verwenden Sie für dieses Beispiel den System.Drawing-Namespace und den System.Windows.Forms-Namespace.

Imports System.Drawing
Imports System.Windows.Forms

Public Class Form1
    Inherits Form

    Public Sub New()
        Dim tabControl1 As New TabControl()
        Dim tabPage1 As New TabPage()
        Dim tabPage2 As New TabPage()
        Dim tabPage3 As New TabPage()
        Dim tabPage4 As New TabPage()
        Dim tabPage5 As New TabPage()
        Dim label1 As New Label()

        tabControl1.Multiline = True
        tabControl1.SizeMode = TabSizeMode.FillToRight
        tabControl1.Padding = New Point(15, 5)
        tabControl1.Controls.AddRange(New Control() {tabPage1, tabPage2, tabPage3, tabPage4, tabPage5})
        tabControl1.Location = New Point(35, 65)
        tabControl1.Size = New Size(220, 180)

        ' Gets the number of tabs currently in the tabControl1 tab strip.
        ' Assigns int value to the tabsInTabStrip variable.
        Dim tabsInTabStrip As Integer = tabControl1.TabCount

        label1.Text = "There are " + tabsInTabStrip.ToString() + " tabs in the tabControl1 tab strip."
        label1.Location = New Point(35, 25)
        label1.Size = New Size(220, 30)

        Size = New Size(300, 300)
        Controls.AddRange(New Control() {label1, tabControl1})
    End Sub

    Shared Sub Main()
        Application.Run(New Form1())
    End Sub
End Class
using System.Drawing;
using System.Windows.Forms;

public class Form1 : Form
{
    public Form1()
    {
        TabControl tabControl1 = new TabControl();
        TabPage tabPage1 = new TabPage();
        TabPage tabPage2 = new TabPage();
        TabPage tabPage3 = new TabPage();
        TabPage tabPage4 = new TabPage();
        TabPage tabPage5 = new TabPage();
        Label label1= new Label();


        tabControl1.Multiline = true;
        tabControl1.SizeMode = TabSizeMode.FillToRight;
        tabControl1.Padding = new Point(15, 5);
        tabControl1.Controls.AddRange(new Control[] {
            tabPage1, tabPage2, tabPage3, tabPage4, tabPage5});
        tabControl1.Location = new Point(35, 65);
        tabControl1.Size = new Size(220, 180);    

        // Gets the number of tabs currently in the tabControl1 tab strip.
        // Assigns int value to the tabsInTabStrip variable.
        int tabsInTabStrip = tabControl1.TabCount;

        label1.Text = "There are " + tabsInTabStrip.ToString() + 
            " tabs in the tabControl1 tab strip.";
        label1.Location = new Point(35, 25);
        label1.Size = new Size(220, 30);

        Size = new Size(300, 300);
        Controls.AddRange(new Control[] {label1, tabControl1});
    }

    static void Main() 
    {
        Application.Run(new Form1());
    }
}
using namespace System::Drawing;
using namespace System::Windows::Forms;
public ref class Form1: public Form
{
public:
   Form1()
   {
      TabControl^ tabControl1 = gcnew TabControl;
      TabPage^ tabPage1 = gcnew TabPage;
      TabPage^ tabPage2 = gcnew TabPage;
      TabPage^ tabPage3 = gcnew TabPage;
      TabPage^ tabPage4 = gcnew TabPage;
      TabPage^ tabPage5 = gcnew TabPage;
      Label^ label1 = gcnew Label;
      tabControl1->Multiline = true;
      tabControl1->SizeMode = TabSizeMode::FillToRight;
      tabControl1->Padding = Point(15,5);
      array<Control^>^tabControls = {tabPage1,tabPage2,tabPage3,tabPage4,tabPage5};
      tabControl1->Controls->AddRange( tabControls );
      tabControl1->Location = Point(35,65);
      tabControl1->Size = System::Drawing::Size( 220, 180 );
      
      // Gets the number of tabs currently in the tabControl1 tab strip.
      // Assigns int value to the tabsInTabStrip variable.
      int tabsInTabStrip = tabControl1->TabCount;
      label1->Text = System::String::Concat( "There are ", tabsInTabStrip, " tabs in the tabControl1 tab strip." );
      label1->Location = Point(35,25);
      label1->Size = System::Drawing::Size( 220, 30 );
      Size = System::Drawing::Size( 300, 300 );
      array<Control^>^formControls = {label1,tabControl1};
      Controls->AddRange( formControls );
   }

};

int main()
{
   Application::Run( gcnew Form1 );
}
import System.Drawing.*;
import System.Windows.Forms.*;

public class Form1 extends Form
{
    public Form1()
    {
        TabControl tabControl1 = new TabControl();
        TabPage tabPage1 = new TabPage();
        TabPage tabPage2 = new TabPage();
        TabPage tabPage3 = new TabPage();
        TabPage tabPage4 = new TabPage();
        TabPage tabPage5 = new TabPage();
        Label label1 = new Label();


        tabControl1.set_Multiline(true);
        tabControl1.set_SizeMode(TabSizeMode.FillToRight);
        tabControl1.set_Padding(new Point(15, 5));
        tabControl1.get_Controls().AddRange(new Control[] {
            tabPage1, tabPage2, tabPage3, tabPage4, tabPage5 });
        tabControl1.set_Location(new Point(35, 65));
        tabControl1.set_Size(new Size(220, 180));
        // Gets the number of tabs currently in the tabControl1 tab strip.
        // Assigns int value to the tabsInTabStrip variable.
        int tabsInTabStrip = tabControl1.get_TabCount();

        label1.set_Text("There are " + ((System.Int32)tabsInTabStrip).ToString()
            + " tabs in the tabControl1 tab strip.");
        label1.set_Location(new Point(35, 25));
        label1.set_Size(new Size(220, 30));

        set_Size(new Size(300, 300));
        get_Controls().AddRange(new Control[] { label1, tabControl1 });
    } //Form1

    public static void main(String[] args)
    {
        Application.Run(new Form1());
    } //main
} //Form1

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

TabControl-Klasse
TabControl-Member
System.Windows.Forms-Namespace