日期:2014-05-18  浏览次数:20685 次

MDI窗体为题
用此代码打开窗体,既不报错也不弹出新窗体,是不是vs有问题了
foreach (Form from1 in this.MdiChildren)//检查窗体是否存在
  {
  if (from1.Name == "xsphb_con")
  {
  return;
  }
  }
  Form xsphbcon = new xsphb_con();
  xsphbcon.MdiParent = this;
  xsphbcon.Show();

------解决方案--------------------
Form xsphbcon = new Form(); 

------解决方案--------------------
要么这样定义
class xsphb_con : Form
{
}

------解决方案--------------------
同意一楼的~

另外检查有无子窗体有很多方法,你可以搜一下~
------解决方案--------------------

foreach (Form from1 in this.MdiChildren)//检查窗体是否存在 

if (from1.Name == "xsphb_con") 

return; 



你这个foreach有意义吗,存在与否都会执行下面的语句啊!
xsphb_con也只是一个窗体的名称,不是类名称,你怎么可以new出来呢
------解决方案--------------------
for (int i = 0; i < this.MdiChildren.Length; i++)
{
if (this.MdiChildren[i].Name == "xsphb_con")
{
this.MdiChildren[i].Activate();
return;
}
}
xsphb_con newMDIChild = new xsphb_con();
newMDIChild.MdiParent = this;
newMDIChild.Show();