MenuStrips and TabPages are Controls. You can add Controls to other Controls as Child controls using Control.Controls.Add(...)
. Use MenuStrip.Dock
to Dock it on the desired position. Maybe you need to set the Size of the MenuStrip.
Although this will work, I'm not sure if this is wise. People don't expect menus to be scattered all around your window. Wouldn't it be better to change the Main menu when you select a different TabPage?
Let every TabPage have its own MenuStrip, and when a new TabPage is selected, let your form change the menu.
class MyTabPage : TabPage
{
...
public MenuStrip MenuStrip => ...
}
If you don't want to create a special TabPage class, consider using property Tag to store the MenuStrip.
In your form:
// probably done in InitializeComponent()
private TabControl tabControl = ...
// access to the TabPages and to the Selected tab:
private IEnumerabl<MyTabPage> TabPages => this.TabControl.TabPages.Cast<MyTabPage>();
private MyTabPage SelectedTabPage => (MyTabPage)this.TabControl.SelectedPage;
// constructor
public MyForm()
{
InitializeComponent();
AddTabPages(); // only if needed
// add the menu strips of all tab pages to this.Controls
IEnumerable<MenuStrip> menuStrips = this.TabPages
.Select(tabPage => tabPage.MenuStrip);
this.Controls.AddRange(menuStrips)
// get notified when selected tab page changes:
this.TabControl.SelectedIndexChanged
tabControl.SelectedIndexChanged += OnTabPageChanged;
}
private MyTabPage SelectedTabPage => (MyTabPage)tabControl.SelectedTab();
private void OnTabPageChanged(object sender, ...)
{
// change the main menu:
this.MainMenuStrip = this.SelectedTabPage?.MenuStrip;
}