Create a main form (FormMain), two sub-forms (FORM1,FORM2), add a MenuStrip control, TabControl control, and add a main menu and two submenus to the menu control, respectively, in the main form, such as:
Then, select the TabControl control property to modify DrawMode = OwnerDrawFixed, and then add it according to the following code: public void Add_tabpage (String str, Form MyForm) { if (Tabcontrolcheckhave (this. Maintabcontrol, str) { &NBSP ; return; &NBSP,} else &N Bsp { maintabcontrol.tabpages.add (str ); maintabcontrol.selecttab (maintabcontrol.tabpages.count-1 ); &NBSP ; myform.formborderstyle = Formborderstyle.none; myform.dock= DockStyle.Fill; myform.toplevel = false; myform.show (); myform.parent = Maintabcontrol.selectedtab; } } public bool Tabcontrolcheckhave (System.Windows.Forms.TabControl tab, String tabname) & nbsp { for (int i = 0; i < tab.) Tabcount; i++) { if (tab . Tabpages[i]. Text = = tabname) { & nbsp tab. SelectedIndex = i; return true; } } &nbs P return false; } private void Form1toolstripmenuitem_click ( Object sender, EventArgs e) { form1 f1= NE W Form1 (); add_tabpage ("F1 People's Republic of China form ", F1); } private void form2toolstripmenuitem_ Click (object sender, EventArgs e) { &NBSP;FORM2 F2 = new Form2 (); add_tabpage ("F2 Korean form ", F2); } private void Maintabcontrol_drawitem ( Object sender, DrawItemeventargs e) { /* If the DrawMode property is set to Ow nerdrawfixed, It raises the DrawItem event whenever TabControl needs to draw one of its tabs */ try { & nbsp this. Maintabcontrol.tabpages[e.index]. BackColor = Color.lightblue; rectangle tabrect = this. Maintabcontrol.gettabrect (E.index); e.graphics.drawstring (this. Maintabcontrol.tabpages[e.index]. Text, this. Font, Systembrushes.controltext, (float) (tabrect.x + 2), (float) (Tabrect.y + 2)); using (pen pen = new Pen (color.white)) &N Bsp { &NBsp tabrect.offset (tabrect.width-15, 2); tabrect.width = 15; tabrect.height = 15; e.graphics.drawrectangle (pen, tabrect); &NBSP,} &NBS P Color color = (E.state = = drawitemstate.selected)? Color.LightBlue:Color.White; using (Brush brush = new SolidBrush (color)) &nbs P { e.gr Aphics. FillRectangle (brush, tabrect); &NBSP,} &NBS P;using (Pen pen2 = new Pen (color.red) { & nbsp point point = new Point (Tabrect.x + 3, Tabrect.y + 3); point point2 = new Point (Tabrect.x + TABRECT.W Idth)-3, (Tabrect.y + tabrect.height)-3); e.graphics.drawline (Pen2, point, Point2); point point3 = new Point (Tabrect.x + 3, (Tabrec T.Y + tabrect.height)-3); point point4 = new Point (Tabrect.x + TABRECT.W Idth)-3, Tabrect.y + 3); e.graphics.drawline (Pen2, Point3, POINT4); } e.graphics.dispose (); &NBSP,} catch (Exception ex)   ; { messagebox.show (E X.message); } } private void Maintabcontrol_mousedown (object sender, MouseEventArgs e) {&NBSP;&N Bsp if (E.button = = MouseButtons.Left) {&nbs p;www.2cto.com int x = e.x; int y = e.y; rectangle tabrect = this. Maintabcontrol.gettabrect (this. maintabcontrol.seLectedindex); tabrect.offset (tabrect.width-0x12, 2); tabrect.width = 15; tabrect.height = 15; if (((X > Tabrect.x && (x < tabrect.right)) & amp;& (Y > Tabrect.y)) && (Y < Tabrect.bottom) & nbsp { this. MainTabControl.TabPages.Remove (this. Maintabcontrol.selectedtab); } } &nbs P }
==
Source: http://blog.csdn.net/w1wqw/article/details/44356439
C # using TabControl controls for multi-form embedding and closing