简体   繁体   English

如何将上面带有tab控件的MDI子窗体加载到您从MDI父菜单栏中选择的特定选项卡上

[英]How do you load a MDI child form that has a tabcontrol on it to a specific tab of your choosing from a MDI parent menustrip

I have two forms. 我有两种形式。 My MDI Parent and MDI child. 我的MDI父母和MDI子女。 on the child form there is a tab control with 4 tabs that each serve their own purpose. 在子窗体上,有一个带有4个选项卡的选项卡控件,每个选项卡都有自己的用途。 on the MDI parent form I have a menustrip that lets you click "Customers". 在MDI父窗体上,我有一个菜单栏,可让您单击“客户”。 from there a dropdown list comes up and you can select like "add new" or "manage customers" and so on. 从那里出现一个下拉列表,您可以选择“添加新”或“管理客户”等。 Each menu item ties to a tab on the tabcontrol. 每个菜单项都绑定到tab控件上的一个选项卡。 Because the tabcontrol only exists on the MDI child form, how do I tell it to load into the child form and pick a tab on the tabcontrol based on which option the user picked in the menustrip? 因为tabcontrol仅存在于MDI子窗体上,我如何告诉它加载到子窗体中并根据用户在菜单栏中选择的选项在tabcontrol上选择一个标签?

Edit: It loads into the child form just fine, I just want it to be able to open to specific tabs 编辑:它可以很好地加载到子窗体中,我只希望它能够打开特定的选项卡

I figured it out. 我想到了。 Just in case anyone is wondering, the tabcontrol on the child form has to be public in the designer and then the line of code is 以防万一有人想知道,子窗体上的tabcontrol必须在设计器中公开,然后代码行是

This would be from Form1 which is the MDI parent form and form2 is the child 这将来自Form1,它是MDI父窗体,而form2是子窗体。

private void YourCommandName_Click (object sender, EventsArgs e)   

    {          
    form2 child = new form2      
    child.MdiParent = this;      
    child.show();     
    child.tabcontrol1.SelectedTab = child.tabpage1;   
    }  

There might be a better way to do it, but that worked for me. 也许有更好的方法可以这样做,但这对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM