Karlovsky120
Karlovsky120

Reputation: 6352

Basic Layout with WindowsForms

How do I create a simple form that has a MenuStrip at the top and a TabControl filling all of the remaining space?

If I go with DockStyle.Top/DockStyke.Fill tabControl fills whole form regardless of MenuStrip:

    public MainWindow()
    {
        initializeComponent();
    }

    private void initializeComponent()
    {
        MenuStrip mainMenu = new MenuStrip();
        mainMenu.Dock = DockStyle.Top;

        TabControl tabs = new TabControl();
        tabs.Dock = DockStyle.Fill;

        TabPage test = new TabPage("test");
        tabs.Controls.Add(test);

        Controls.Add(mainMenu);
        Controls.Add(tabs);
    }

Upvotes: 2

Views: 50

Answers (2)

Fabio
Fabio

Reputation: 32445

Another approach through designer, without writing code manually, so your changes will affect design time too

Use Document outline tab and arrange control's hierarchy with your requirements

View -> Other Windows -> Document outline or CTRL+ALT+T

Upvotes: 0

Reza Aghaei
Reza Aghaei

Reputation: 125197

You should change the z-order of mainMenu or tabs. For example you can call:

mainMenu.SendToBack();

//Or
//tabs.BringToFront();

After adding controls to the controls collection.

Upvotes: 2

Related Questions