C # Winform tab integration form,

Source: Internet
Author: User

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 );}}}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.