次の方法で共有


TabControl.TabCount プロパティ

タブ ストリップにあるタブの数を取得します。

Public ReadOnly Property TabCount As Integer
[C#]
public int TabCount {get;}
[C++]
public: __property int get_TabCount();
[JScript]
public function get TabCount() : int;

プロパティ値

タブ ストリップにあるタブの数。

使用例

[Visual Basic, C#, C++] 5 つの TabPage オブジェクトを持つ TabControl を作成する例を次に示します。この例では、 TabCount プロパティを使用して、 tabControl1 タブ ストリップ内の現在のタブ数を取得します。

[Visual Basic, C#, C++] この例では、 System.Drawing 名前空間と System.Windows.Forms 名前空間を使用します。

 
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

[C#] 
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());
    }
}

[C++] 
using namespace System::Drawing;
using namespace System::Windows::Forms;

public __gc class Form1 : public 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 = Point(15, 5);
        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(S"There are ", 
            __box(tabsInTabStrip), S" tabs in the tabControl1 tab strip.");
        label1->Location = Point(35, 25);
        label1->Size = System::Drawing::Size(220, 30);
        Size = System::Drawing::Size(300, 300);
        Control* formControls[] = {label1, tabControl1};
        Controls->AddRange(formControls);
    }
};

int main() {
    Application::Run(new Form1());
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

TabControl クラス | TabControl メンバ | System.Windows.Forms 名前空間