- okok云
-
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace WindowsApplication21
{
/// <summary>
/// Form2 的摘要说明。
/// </summary>
public class Form2 : System.Windows.Forms.Form
{
private bool flag = false;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.Button button1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form2()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.panel2 = new System.Windows.Forms.Panel();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// panel1
//
this.panel1.BackColor = System.Drawing.Color.IndianRed;
this.panel1.Location = new System.Drawing.Point(32, 32);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(152, 48);
this.panel1.TabIndex = 0;
//
// panel2
//
this.panel2.BackColor = System.Drawing.Color.SpringGreen;
this.panel2.Location = new System.Drawing.Point(98, 64);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(96, 80);
this.panel2.TabIndex = 1;
//
// button1
//
this.button1.Location = new System.Drawing.Point(96, 200);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(128, 56);
this.button1.TabIndex = 2;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form2
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.panel2);
this.Controls.Add(this.button1);
this.Controls.Add(this.panel1);
this.Name = "Form2";
this.Text = "Form2";
this.ResumeLayout(false);
}
#endregion
private void button1_Click(object sender, System.EventArgs e)
{
if (flag)
this.panel1.SendToBack();
else
this.panel2.SendToBack();
flag = !flag;
}
}
}
- meira
-
自己修改一下设计器生成的代码.
下面这句是把panel2添加到panel1上,
this.panel1.Controls.Add(this.panel2);
如果改成:
this.Controls.Add(this.panel2);
就是把panel2直接添加到form上.
所在的文件名:Form1.Designer.cs
还有不会你可以把你的项目发给我,我帮你改.
- 再也不做稀饭了
-
这样太麻烦了
早点抛弃
像你这样把这么多Panel放一个页面上 以后维护 或者修改啥的 都太费劲了
- 里论外几
-
没有额。你添加的时候可以切换到HTML源代码,然后插入控件。或者自己手动写Panel控件也一样。