我有一个MDIParent和一个菜单条,所以当我单击一个StripMenuitem时,在我的MdiParent表单中会显示另一个表单,所以我的问题是:在MdiParent中打开的表单的Form_Load事件不起作用!,似乎我必须使用另一个事件:/
有什么想法吗?谢谢
下面是如何在MdiParent表单中显示表单的代码
FormVehicule FV;
private void véhiculeToolStripMenuItem_Click(object sender, EventArgs e)
{
if (FV == null)
{
FV = new FormVehicule();
FV.MdiParent = this;
FV.WindowState = FormWindowState.Maximized;
FV.Show();
}
else
{
FV.WindowState = FormWindowState.Maximized;
FV.Show();
FV.BringToFront();
}
}因此,在子窗体FormVehicule的代码中
private void FormVehicule_Load(object sender, EventArgs e)
{
comboBoxUnite.SelectedIndex = 0;
U = new Unite(FormLogin.Con);
U.Lister();
for (int i = 0; i < U.C.Dt.Rows.Count; i++)
comboBoxUnite.Items.Add(U.C.Dt.Rows[i][0].ToString());
comboBoxConducteur.SelectedIndex = 0;
C = new Conducteur(FormLogin.Con);
C.Lister();
for (int i = 0; i < C.C.Dt.Rows.Count; i++)
comboBoxConducteur.Items.Add(C.C.Dt.Rows[i][0].ToString());
V = new Vehicule(FormLogin.Con);
V.Lister();
dataGridViewVehicule.DataSource = V.C.Dt;
MessageBox.Show("Test");
}发布于 2012-02-17 23:02:11
如何处理Form.Load事件?
同样的代码也适用于我:
void toolStripMenuItem1_Click(object sender, EventArgs e) {
Form childForm = new Form();
childForm.MdiParent = this;
childForm.Load += childForm_Load; // subscribe the Form.Load event before Form.Show()
childForm.Show(); // event will be raised from here
}
void childForm_Load(object sender, EventArgs e) {
// ...
}您还可以使用以下方法:
void toolStripMenuItem1_Click(object sender, EventArgs e) {
MyChildForm form = new MyChildForm();
form.MdiParent = this;
form.Show();
}
class MyChildForm : Form {
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
//...
}
}https://stackoverflow.com/questions/9330215
复制相似问题