我现在正在制作一个链接到多个不同表单(“添加项目”、“关于”等)的 MDI。我不认为上下文太重要,因为我的问题是当我编辑不同的子表单时,当我运行程序时新版本不会显示。我包含了父表单 (frmParent) 和添加项目表单 (frmAdd) 中的完整代码
namespace MDIDemo
{
public partial class frmParent : Form
{
public static LibraryClass l1 = new LibraryClass();
public frmParent()
{
InitializeComponent();
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
// Allocate memory for our about box
frmAboutBox frmAbt = new frmAboutBox();
// Assign the parent:
frmAbt.MdiParent = this; // This is the parent/main form
frmAbt.Show();
}
private void closeToolStripMenuItem_Click(object sender, EventArgs e)
{
if (ActiveMdiChild != null)
{
ActiveMdiChild.Close();
}
}
private void closeAllToolStripMenuItem_Click(object sender, EventArgs e)
{
while (ActiveMdiChild != null)
{
ActiveMdiChild.Close();
}
}
private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
}
private void cascadeToolStripMenuItem_Click(object sender, EventArgs e)
{
this.LayoutMdi(MdiLayout.Cascade);
}
private void tileHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
{
this.LayoutMdi(MdiLayout.TileHorizontal);
}
private void tileVerticalToolStripMenuItem_Click(object sender, EventArgs e)
{
this.LayoutMdi(MdiLayout.TileVertical);
}
private void arrangeIconsToolStripMenuItem_Click(object sender, EventArgs e)
{
this.LayoutMdi(MdiLayout.ArrangeIcons);
}
private void addToolStripMenuItem_Click(object sender, EventArgs e)
{
// Allocate memory for our add box
frmAdd add1 = new frmAdd();
// Assign the parent:
add1.MdiParent = this; // This is the parent/main form
add1.Show();
}
private void showItemsToolStripMenuItem_Click(object sender, EventArgs e)
{
frmShow show1 = new frmShow();
show1.MdiParent = this;
show1.Show();
}
}
}
namespace MDIDemo
{
public partial class frmAdd : Form
{
public frmAdd()
{
InitializeComponent();
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnClr_Click(object sender, EventArgs e)
{
txtISBN.Clear();
txtAuth.Clear();
numNum.Value = 0;
}
private void btnAdd_Click(object sender, EventArgs e)
{
ItemRec item1;
item1.iSBN = "ISBN";
item1.AuthorName = "Last First";
item1.numOwned = 0;
item1.numOnLoan = 0;
try
{
item1.iSBN = txtISBN.Text;
item1.AuthorName = txtAuth.Text;
item1.numOwned = Convert.ToInt32(numNum.Value);
}
catch (Exception ex)
{
MessageBox.Show(txtISBN.Text + " is not an integer.",
"Data entry error",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
// Add the item to our list:
try
{
frmParent.l1.Insert(item1);
}
catch (ListIsFullException ex)
{
MessageBox.Show(ex.Message,
"Data entry error",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private void frmAdd_Load(object sender, EventArgs e)
{
}
}
}
我不知道要尝试什么,我尝试简单地删除并重新输入声明之类的东西,但(毫不奇怪)这似乎没有做任何事情。
好的,我修好了。首先,我尝试删除 bin 文件夹,然后重建解决方案,但这不起作用,所以我后退一步,我认为我删除了项目文件夹,然后尝试重建,但它不起作用,所以我取消了删除并运行它,我相信之后它就起作用了。我很困惑,但至少它正在运行。如果有人知道为什么会发生这种情况并想分享,请随意。