まるまるこふこふ

数々の次元が崩壊し、全ての生命が塵と化すのを見てきた。私ほどの闇の心の持ち主でも、そこには何の喜びも無かった。

動的にTabControlを作る

//TabPageを保存する配列
private TabPage[] TabPages;

private void Main_Load(object sender, EventArgs e)
{
    //コントロールの描画を一旦止める
    this.SuspendLayout();

    // tabControl
    TabControl MainTabControl = new System.Windows.Forms.TabControl();

    MainTabControl.Location = new System.Drawing.Point(13, 13);
    MainTabControl.Name = "tabControl1";
    MainTabControl.SelectedIndex = 0;
    MainTabControl.Size = new System.Drawing.Size(259, 237);
    MainTabControl.TabIndex = 0;
    this.Controls.Add(MainTabControl);

    //TabPage
    //今回はTabPageを5つ作る
    this.TabPages = new System.Windows.Forms.TabPage[5];
    for (int i = 0; i < this.TabPages.Length; i++)
    {
        this.TabPages[i] = new System.Windows.Forms.TabPage();
        this.TabPages[i].Name = "tabPage" + i.ToString();
        this.TabPages[i].Text = "tabPage" + i.ToString();

        MainTabControl.Controls.Add(this.TabPages[i]);
    }
    //コントロールの描画を再開
    this.ResumeLayout(false);
}