第二种形式没有正确显示

时间:2014-12-18 15:17:32

标签: c# windows-forms-designer mdi

我的主要表单是带有菜单条的mdi容器。当我选择Options-Maintenance时,我希望出现另一个mdi。这种作品。而不是另外一个mdi容器以及设计,会出现一个规则的较小形式,但不确定原因。

 public partial class mdiMain : Form
{
    static string sTo = ConfigurationManager.ConnectionStrings["connectionTo"].ToString();
    public myDataAccess3 data;

    public mdiMain()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        try
        {
            data = new myDataAccess3(sTo);
            frmLogOn frmLogOn = new frmLogOn(data);
            if (frmLogOn.ShowDialog().Equals(DialogResult.Cancel))
            {
                frmLogOn.Close();
                frmLogOn = null;
                Application.Exit();
                return;
            }
            frmLogOn.Close();
            frmLogOn = null;
            this.Focus();
        }
        catch (Exception e1)
        {

            MessageBox.Show("There was an error " + e1);
        }
    }

    private void maintenanceToolStripMenuItem_Click(object sender, EventArgs e)
    {

        mdiMaintenance maintenance = new mdiMaintenance(this,data);
        maintenance.Enabled = true;
        maintenance.Show();
    }
}

 public partial class mdiMaintenance : Form
{
    private myDataAccess3 data;
    private mdiMain mdiMain;

    public mdiMaintenance()
    {
        InitializeComponent();
    }


    public mdiMaintenance(mdiMain mdiMain, myDataAccess3 data)
    {
        // TODO: Complete member initialization
        this.mdiMain = mdiMain;
        this.data = data;
    }

    private void mdiMaintenance_Load(object sender, EventArgs e)
    {

    }

感谢您的帮助

1 个答案:

答案 0 :(得分:1)

如果表单是MDI 孩子,那么您需要设置MdiParent属性:

private void maintenanceToolStripMenuItem_Click(object sender, EventArgs e)
{
    mdiMaintenance maintenance = new mdiMaintenance(this,data);
    maintenance.Enabled = true;
    maintenance.MdiParent = this;
    maintenance.Show();
}