private void button1_Click(object sender, EventArgs e) { this.initButton(); this.button1.BackColor = Color.FromArgb(95, 129, 174); XHomePage cform = new XHomePage();//实例化一个子窗口 //设置子窗口不显示为顶级窗口 cform.TopLevel = false; //设置子窗口的样式,没有上面的标题栏 cform.FormBorderStyle = FormBorderStyle.None; //填充 cform.Dock = DockStyle.Fill; //清空控件 this.pnlCenter.Controls.Clear(); //加入控件 this.pnlCenter.Controls.Add(cform); //让窗体显示 cform.Show(); // try // { // this.initButton(); // this.button1.BackColor = Color.FromArgb(95, 129, 174); // Monitor.Enter(this.lockObj); // if (!formSwitchFlag) // { // formSwitchFlag = true; // this.ShowForm(pnlCenter, form1); // formSwitchFlag = false; // } // else // { // return; // } // } //#pragma warning disable CS0168 // 声明了变量“ex”,但从未使用过 // catch (System.Exception ex) //#pragma warning restore CS0168 // 声明了变量“ex”,但从未使用过 // { // // // } // finally // { // Monitor.Exit(this.lockObj); // } }
/*public void ShowForm(System.Windows.Forms.Panel panel, System.Windows.Forms.Form frm) * { * lock (this) * { * try * { * if (this.currentForm != null && this.currentForm == frm) * { * return; * } * else if (this.currentForm != null) * { * if (this.ActiveMdiChild != null) * { * this.ActiveMdiChild.Hide(); * } * } * this.currentForm = frm; * frm.TopLevel = false; * frm.MdiParent = this; * panel.Controls.Clear(); * panel.Controls.Add(frm); * frm.Show(); * frm.Dock = System.Windows.Forms.DockStyle.Fill; * this.Refresh(); * foreach (Control item in frm.Controls) * { * item.Focus(); * break; * } * } #pragma warning disable CS0168 // 声明了变量“ex”,但从未使用过 * catch (System.Exception ex) #pragma warning restore CS0168 // 声明了变量“ex”,但从未使用过 * { * // * } * } * }*/ private void button1_Click(object sender, EventArgs e) { this.initButton(); this.button1.BackColor = Color.FromArgb(95, 129, 174); XHomePage cform = new XHomePage();//实例化一个子窗口 //设置子窗口不显示为顶级窗口 cform.TopLevel = false; //设置子窗口的样式,没有上面的标题栏 cform.FormBorderStyle = FormBorderStyle.None; //填充 cform.Dock = DockStyle.Fill; //清空控件 this.pnlCenter.Controls.Clear(); //加入控件 this.pnlCenter.Controls.Add(cform); //让窗体显示 cform.Show(); }