110,539
社区成员
发帖
与我相关
我的任务
分享
panel1.Controls.Add(stfrm1);
stfrm1.Show()
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
}
class MainForm:Form
{
private TreeView treeView1;
private Panel panel1;
public MainForm()
{
this.InitializeComponent();
LoginInDialog login = new LoginInDialog();
this.treeView1.Nodes[0].Tag = login;
WelcomeDialog welcome = new WelcomeDialog();
this.treeView1.Nodes[1].Tag = welcome;
}
private void InitializeComponent()
{
System.Windows.Forms.TreeNode treeNode1 = new System.Windows.Forms.TreeNode("Welcome");
System.Windows.Forms.TreeNode treeNode2 = new System.Windows.Forms.TreeNode("Login");
this.treeView1 = new System.Windows.Forms.TreeView();
this.panel1 = new System.Windows.Forms.Panel();
this.treeView1.Dock = System.Windows.Forms.DockStyle.Left;
this.treeView1.Location = new System.Drawing.Point(0, 0);
this.treeView1.Name = "treeView1";
treeNode1.Name = "Node0";
treeNode1.Text = "Welcome";
treeNode2.Name = "Node1";
treeNode2.Text = "Login";
this.treeView1.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {
treeNode1,
treeNode2});
this.treeView1.Size = new System.Drawing.Size(188, 380);
this.treeView1.TabIndex = 0;
this.treeView1.NodeMouseClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.treeView1_NodeMouseClick);
this.Controls.Add(this.treeView1);
this.panel1.Dock = System.Windows.Forms.DockStyle.Right;
this.panel1.Location = new System.Drawing.Point(194, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(358, 380);
this.ClientSize = new System.Drawing.Size(552, 380);
this.Controls.Add(this.panel1);
this.Controls.Add(this.treeView1);
this.Name = "MainForm";
this.ResumeLayout(false);
}
private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
this.panel1.Controls.Clear();
this.panel1.Controls.Add(e.Node.Tag as Control);
}
}
class WelcomeDialog:UserControl
{
public WelcomeDialog()
{
this.InitializeComponent();
}
#region Component Designer generated code
private void InitializeComponent()
{
this.linkLabel1 = new System.Windows.Forms.LinkLabel();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.linkLabel1.AutoSize = true;
this.linkLabel1.Location = new System.Drawing.Point(117, 19);
this.linkLabel1.Name = "linkLabel1";
this.linkLabel1.Size = new System.Drawing.Size(111, 13);
this.linkLabel1.TabIndex = 0;
this.linkLabel1.TabStop = true;
this.linkLabel1.Text = "http://www.csdn.net/";
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(19, 19);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(67, 13);
this.label1.TabIndex = 1;
this.label1.Text = "Welcome to:";
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(19, 56);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(277, 13);
this.label2.TabIndex = 2;
this.label2.Text = "Copyright © 1999-2010, CSDN.NET, All Rights Reserved";
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.linkLabel1);
this.Name = "WelcomeDialog";
this.Size = new System.Drawing.Size(299, 269);
}
#endregion
private System.Windows.Forms.LinkLabel linkLabel1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
}
class LoginInDialog:UserControl
{
public LoginInDialog()
{
this.InitializeComponent();
}
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(31, 28);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(60, 13);
this.label1.TabIndex = 0;
this.label1.Text = "UserName:";
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(34, 77);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(56, 13);
this.label2.TabIndex = 1;
this.label2.Text = "Password:";
this.textBox1.Location = new System.Drawing.Point(113, 28);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(130, 20);
this.textBox1.TabIndex = 2;
this.textBox2.Location = new System.Drawing.Point(113, 70);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(130, 20);
this.textBox2.TabIndex = 2;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "LoginInDialog";
this.Size = new System.Drawing.Size(297, 262);
}
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
}
}