[请教] 我的这段代码怎么一到执行打开子窗口的时候,就提示错误呢?
using System;using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace 图书管理系统
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
private bool checkChildFrmExist(string childFrmName)
{
foreach(Form childFrm in this.MdiChildren)
{
if(childFrm.Name == childFrmName) //用子窗体的Name进行判断,如果存在则将他激活
{
if(childFrm.WindowState == FormWindowState.Minimized)
childFrm.WindowState = FormWindowState.Normal;
childFrm.Activate();
return true;
}
}
return false;
}
private void 退出ToolStripMenuItem1Click(object sender, EventArgs e)
{
this.Close();
return;
}
private void 关于ToolStripMenuItem1Click(object sender, EventArgs e)
{
about SubForm = new about();
SubForm.ShowDialog();
}
private void 藏书管理ToolStripMenuItemClick(object sender, EventArgs e)
{
if (this.checkChildFrmExist("cangshu") == true)
{
return;
}
cangshu newFom = new cangshu();
newFom.MdiParent = this;
newFom.Show();
}
}
}
请教上述代码中,为什么一打开菜单中的子窗口就会提示newFom.MdiParent = this;这一句有问题呢。我用sharpdevelop的。