子窗体改变父窗体的菜单属性

来源:百度知道 编辑:UC知道 时间:2024/06/08 10:19:50
在父窗体的Load事件中有如下代码:
private void FrmMain_Load(object sender, EventArgs e)
{
货物管理MToolStripMenuItem.Enabled = false;
供应商管理GToolStripMenuItem.Enabled = false;
}
在子窗体的中如何将
货物管理MToolStripMenuItem.Enabled 改为true,
供应商管理GToolStripMenuItem.Enabled 改为true?
子窗体的代码是:
string ConnectStr = "server=localhost;database=ClassDesign;uid=sa;pwd=;";
SqlConnection mycon = new SqlConnection(ConnectStr);
try
{

mycon.Open();
MessageBox.Show("连接成功");
this.MdiParent.Text += " —已登录";
this.Hide();
}
catch
{
MessageBox.Show("连接失败","连接出错");
return;
}

在父窗体中写一个方法:
public void updateMenu()
{
this.供应商管理ToolStripMenuItem.Enabled = true;
this.货物管理ToolStripMenuItem.Enabled = true;
}

在子窗体中:

private void Form2_Load(object sender, EventArgs e)
{
Form1 f = (Form1)this.ParentForm;
f.updateMenu();
}

构造函数重载

事件委托!
可以找些资料看一下,用法很广。