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();
}
}
}
这段代码可以满足你的要求,打开子窗体的代码是用菜单的单击事件触发的
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();
}
}
}
这段代码可以满足你的要求,打开子窗体的代码是用菜单的单击事件触发的
解决方案 »
- 可以难到大家吗?TCP通讯
- 关于求对数的问题
- 如何把vs.net代码转成类图?
- C# winform 怎么实现listbox的两种功能呢,一是拖动功能,二是也可以实现双击触发另一个操作,我现在的问题是双击的时候是先触发拖动功能,双击操作不起作用,谁知道告诉本姑娘一下,急着用,谢谢!
- Graphics画线用DrawLine的问题?
- 关于GDI+问题寻解
- 有个问题请大家帮忙解决下
- 对Oracle数据库不熟,想请问 ...
- 求大神 获取url返回的数据
- c#调用ocx控件,返回值为空,100分求高手帮忙,急!!!
- 关于代表中的参数问题!(保证结帖)
- 请教专家:如果捕获在DataGrid上添加数据不合法,产生的NoNullAllowedException?我想自定义出错信息。
label的mouse down,up,move 事件中控制treeview ,listbox的尺寸.