C # Winform tab integration form,
Knowledge points: Use reflection to dynamically load the form to the corresponding TabPage.
Using System; using System. collections. generic; using System. componentModel; using System. data; using System. drawing; using System. linq; using System. reflection; using System. text; using System. threading. tasks; using System. windows. forms; namespace MDITest {public partial class MainForm: Form {public MainForm () {InitializeComponent ();} public int [] s = {0, 0, 0 }; // used to record whether the form has opened private void MainForm_Load (object sender, EventArgs e) {// by default, the CNC form string formClass = "MDITest. CNC "; GenerateForm (formClass, tabControl1);} public void GenerateForm (string form, object sender) {// Form fm = (Form) Assembly is generated by reflection. getExecutingAssembly (). createInstance (form); // set the form without borders and add it to the tab fm. formBorderStyle = FormBorderStyle. none; fm. topLevel = false; fm. parent = (TabControl) sender ). selectedTab; fm. controlBox = false; fm. dock = DockStyle. fill; fm. show (); s [(TabControl) sender ). selectedIndex] = 1;} private void tabcontrolpolicselectedindexchanged (object sender, EventArgs e) {// only generate if (s [tabControl1.SelectedIndex] = 0) {btn_Click (sender, e) ;}//< summary> /// click the common button to display the corresponding form on the tab /// </summary> private void btn_Click (object sender, eventArgs e) {string formClass = (TabControl) sender ). selectedTab. tag. toString (); GenerateForm (formClass, sender );}}}