我创建了两个表单:一个登录表单,以及一个在我开始调试时显示的主表单。加载主表单时,登录表单也已加载。现在我的问题是,我想在加载登录表单时禁用主表单。如果连接成功,则必须启用主窗体,否则应禁用。
我试过这段代码:
MainFrm .cs :
private void Form1_Load(object sender, EventArgs e)
{
foreach (Control c in this.Controls)
c.Enabled = false;
Connectez ConnectezFrm = new Connectez { TopMost = true, Owner = this };
ConnectezFrm.Show();
}
Connectez.cs:
private MainFrm objMainfrm { get; set; }
public Connectez(MainFrm objfrm)
{
objMainfrm = objfrm;
InitializeComponent();
}
....
....
private void simpleButton1_Click(object sender, EventArgs e)
{
foreach (Control c in objMainfrm.Controls)
c.Enabled = true;
this.Close();
}