0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

C# - TabControl, TabPageのサンプル コードべた書き(Visual Studio不使用)

Last updated at Posted at 2020-10-17

目次: C# - Windows Formsでよく使うコントロールたち (Visual Studioなし環境向け) - Qiita

まえがき

意外とTabControl&TabPageを使うサンプルソースがサクッと見つからなかったので、メモ代わりに置いておきます。

キャプチャ

image.png

ソースコード

TabControlにタブTabPageを登録して使います。


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

class SampleForm : Form
{
    TabControl tabc;
    TabPage    tabp1;
    TabPage    tabp2;

    SampleForm()
    {
        ClientSize = new Size(500, 300);

        Controls.Add(tabc = new TabControl(){
            Dock = DockStyle.Fill,
        });

        tabp1 = new TabPage(){
            Text = "Sample Page #1",
            Dock = DockStyle.Fill,
        };
        tabc.TabPages.Add(tabp1);

        tabp2 = new TabPage(){
            Text = "Sample Page #2",
            Dock = DockStyle.Fill,
        };
        tabc.TabPages.Add(tabp2);


        tabp1.Controls.Add(new Button(){
            Text="Button on tabp1",
            Dock = DockStyle.Fill,
        });

        tabp2.Controls.Add(new Button(){
            Text="Button on tabp2",
            Dock = DockStyle.Fill,
        });
    }
    
    [STAThread]
    static void Main(string[] args)
    {
        Application.Run(new SampleForm());
    }
}

参考サイト

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?