Embed a form onto a tabcontrol in windows forms

后端 未结 5 1591
你的背包
你的背包 2020-12-11 03:36

I have a tab control in a windows form and I want to be able to click on a tab and in the body area of the tab I want it to display another form as an embedded component. I

相关标签:
5条回答
  • 2020-12-11 03:45

    You are probably looking for Tabbed MDI Child Forms

    0 讨论(0)
  • 2020-12-11 03:48

    If you do not want to use MDI, you can try to put everything from desired form to user control and add this user control in both form and tab.

    0 讨论(0)
  • 2020-12-11 03:57

    You can embed a Form but it's not the best choice.

    Better place the contents on UserControls and add that to the TabPage.

    0 讨论(0)
  • 2020-12-11 03:57

    I think the other answer has the right idea; Tabbed MDI is probably what you want.

    There is an approach where you create a UserControl that has the same content as the form and use that on the TabPage.

    TabPage myTabPage = new TabPage(sometext);
    myUserControl = new myUserControlType();
    myUserControl.Dock = DockStyle.Fill;
    myTabPage.Controls.Add(myUserControl);
    myTabControl.Add(myTabPage);
    

    http://bytes.com/topic/c-sharp/answers/270457-can-i-add-form-tabpage goes into more detail; but I'd look at the MDI stuff first.

    0 讨论(0)
  • 2020-12-11 04:04

    Set your MainForm (Parent) as IsMDIContainer = true;

    Create an instance of the ChildForm and call this function:

    FormChild frmChild = new FormChild();
    AddNewTab(frmChild);
    

    Copy this Function to your code:

    private void AddNewTab(Form frm)
    {
    
        TabPage tab = new TabPage(frm.Text);
    
        frm.TopLevel = false;
    
        frm.Parent = tab;
    
        frm.Visible = true;
    
        tabControl.TabPages.Add(tab);
    
        frm.Location = new Point((tab.Width - frm.Width) / 2, (tab.Height - frm.Height) / 2);
    
        tabControl.SelectedTab = tab;
    
    }
    
    0 讨论(0)
提交回复
热议问题