使用c#启用子窗体中的菜单条

时间:2016-01-11 12:16:06

标签: c# winforms

如何以子格式启用菜单条?

我只想在关闭子表单时启用菜单按钮条 如何以子格式编码?

学生....

private void tsmNewEmp_Click(object sender, EventArgs e)
{
    if(NewEmp == null)
    {
        NewEmp = new NewEmployee();
        NewEmp.MdiParent = this;
    }
    NewEmp.Show();
    tsmNewEmp.Enabled = false;
    tsmNewContract.Enabled = false;
}

2 个答案:

答案 0 :(得分:0)

您可以在儿童关闭后使用FormClosed事件更新父表单中的按钮:

private void tsmNewEmp_Click(object sender, EventArgs e)
{
    if(NewEmp == null)
    {
        NewEmp = new NewEmployee();
        NewEmp.MdiParent = this;
        NewEmp.FormClosed += FormClosed_1;
    }
    NewEmp.Show();
    tsmNewEmp.Enabled = false;
    tsmNewContract.Enabled = false;
}

private void FormClosed_1(object sender, FormClosedEventArgs e)
{
    tsmNewEmp.Enabled = true;
    tsmNewContract.Enabled = true;
}

答案 1 :(得分:0)

Control [] controls = this.MdiParent.Controls.Find(“Menu”,true);             foreach(在控件中控制ctrl)             {                 if(ctrl.Name ==“Menu”)                 {                     MenuStrip strip = ctrl as MenuStrip;                     strip.Items [“login”]。Enabled = false;                     strip.Items [“logout”]。Enabled = false;                 }             }