using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;namespace 窗体应用
{
/// <summary>
/// Summary description for Form6.
/// </summary>
public class Form6 : System.Windows.Forms.Form
{
private System.Drawing.Printing.PrintDocument printDocument1;
private System.Windows.Forms.PrintDialog printDialog1;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Splitter splitter1;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.TreeView treeView1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null; public Form6()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
} /// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.printDialog1 = new System.Windows.Forms.PrintDialog();
this.printDocument1 = new System.Drawing.Printing.PrintDocument();
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.panel1 = new System.Windows.Forms.Panel();
this.splitter1 = new System.Windows.Forms.Splitter();
this.panel2 = new System.Windows.Forms.Panel();
this.treeView1 = new System.Windows.Forms.TreeView();
this.panel2.SuspendLayout();
this.SuspendLayout();
// 
// printDocument1
// 
this.printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.printDocument1_PrintPage);
// 
// mainMenu1
// 
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  this.menuItem1});
// 
// menuItem1
// 
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  this.menuItem2});
this.menuItem1.Text = "File";
// 
// menuItem2
// 
this.menuItem2.Index = 0;
this.menuItem2.Text = "打开子窗体";
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
// 
// panel1
// 
this.panel1.Dock = System.Windows.Forms.DockStyle.Right;
this.panel1.Location = new System.Drawing.Point(148, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(144, 266);
this.panel1.TabIndex = 0;
// 
// splitter1
// 
this.splitter1.Dock = System.Windows.Forms.DockStyle.Right;
this.splitter1.Location = new System.Drawing.Point(140, 0);
this.splitter1.Name = "splitter1";
this.splitter1.Size = new System.Drawing.Size(8, 266);
this.splitter1.TabIndex = 1;
this.splitter1.TabStop = false;
// 
// panel2
// 
this.panel2.Controls.AddRange(new System.Windows.Forms.Control[] {
 this.treeView1});
this.panel2.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(140, 266);
this.panel2.TabIndex = 2;
// 
// treeView1
// 
this.treeView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.treeView1.ImageIndex = -1;
this.treeView1.Name = "treeView1";
this.treeView1.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {
  new System.Windows.Forms.TreeNode("Root", new System.Windows.Forms.TreeNode[] {
new System.Windows.Forms.TreeNode("Node1"),
new System.Windows.Forms.TreeNode("Node3"),
new System.Windows.Forms.TreeNode("Node4")})});
this.treeView1.SelectedImageIndex = -1;
this.treeView1.Size = new System.Drawing.Size(140, 266);
this.treeView1.TabIndex = 0;
// 
// Form6
// 
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
  this.panel2,
  this.splitter1,
  this.panel1});
this.HelpButton = true;
this.Menu = this.mainMenu1;
this.Name = "Form6";
this.Text = "Form6";
this.panel2.ResumeLayout(false);
this.ResumeLayout(false); }
#endregion static void Main() 
{
Application.Run(new Form6());
}
private void menuItem2_Click(object sender, System.EventArgs e)
{
Form f = new Form();
f.TopLevel = false;
f.Parent = this.panel1;
f.Dock = DockStyle.Bottom;
f.BackColor = Color.Red;
f.Show();
}
}
}
这段代码可以满足你的要求,打开子窗体的代码是用菜单的单击事件触发的