首页 > 解决方案 > MDI 儿童对接问题

问题描述

我正在使用 C# Windows 窗体。我有一个 MDI 应用程序,其面板固定在 MDI 表单的左侧。我正在最大化打开 MDI 子窗口,效果很好。但是,我有两个单独的问题,它们可能是相关的,它们是:

当我单击 MDI 子窗体上的恢复按钮时,窗体进入 MDI 父窗体中间的一种伪最小化状态。不可能调整它的大小并拉伸它,甚至移动它。然后我可以最小化它(到父级的底部),恢复它(到同样奇怪的伪最小化状态)或像以前一样最大化它。我如何让它进入正常状态... errr... 通常。

正在发生的另一个可能相关也可能不相关的影响是,当我打开子项时,表单的标题栏没有与 MDI 菜单集成。有子窗口栏,然后是 MDI 菜单栏。通常这些集成。

我制作了一个短视频来演示这一点,一张图片值一千字,在这里:https ://youtu.be/l1yFeDFJeMQ

为清楚起见,MDI 父级的名称为“mdi”。MDI 子窗体的名称是“frmForm”。这听起来可能很奇怪,但“frmForm”的目的是让您能够设计表单。

MDI父窗体中的调用代码是这样的:

private bool EditForm(AppData.Server oServer, AppData.App oApp, int iFrmID)
{   
    // this edits the form passed within the indicated Appster server/app.
    frmForm oFrmForm;

    try
    {
        oFrmForm = new frmForm();
        if (!oFrmForm.EditForm(_owner, _g, oServer, oApp, iFrmID)) throw new Exception("Cannot show form for editing.");

        return true;
    }
    catch (Exception ex)
    {
        _g.Errs.Raise(ex);
        return false;
    }
}

MDI子窗体中的代码在这里:

public bool EditForm(Form oMDIParent, AppData.Globals oG, AppData.Server oServer, AppData.App oApp, int iFrmID)
{
    try
    {
        _g = oG;
        _app = oApp;
        _server = oServer;
        _mode = Dolphin.enumFormEditMode.Edit;

        toolbox.Init(_g, (TextBox)fd.Controls["txtDebug"]);
        fd.Init(_g, _server);
        fd.SnapToGrid = true;
        
        svEvents.Init(_g);
        svSteps.Init(_g);

        if (!ReadData(iFrmID)) throw new Exception("Could not read form data.");
        if (!PopulateParams()) throw new Exception("Could not populate parameters list correctly.");
        if (!PopulateQueries()) throw new Exception("Could not populate queries list correctly.");
        if (!PopulateModes()) throw new Exception("Could not populate modes list correctly.");
        if (!PopulateControls()) throw new Exception("Could not populate controls list correctly.");
        if (!PopulatePropControls(false)) throw new Exception("Could not populate properties control dropdown correctly.");
        if (!PopulatePropMode(false)) throw new Exception("Could not populate properties mode dropdown correctly.");
        if (!ShowData()) throw new Exception("Could not populate with form data.");
        //if (!SetControlAccess()) throw new Exception("Could not set access to controls correctly.");
        _isDirty = false; // has to happen after all the fields are setup
        if (!ValidateCtrlXml()) throw new Exception("Could not validate XML for controls."); // might set the form dirty if it has to make changes
        if (!SetFormTitle()) throw new Exception("Could not set title.");

        _g.DatProp.AddSubscriber(new DatPropSubscription(this, _server.ConnectionName, "Ctrl"));
        _g.DatProp.AddSubscriber(new DatPropSubscription(this, _server.ConnectionName, "Event"));
        _g.DatProp.AddSubscriber(new DatPropSubscription(this, _server.ConnectionName, "FrmMode"));
        _g.DatProp.AddSubscriber(new DatPropSubscription(this, _server.ConnectionName, "FrmParam"));
        _g.DatProp.AddSubscriber(new DatPropSubscription(this, _server.ConnectionName, "FrmQuery"));
        _g.DatProp.AddSubscriber(new DatPropSubscription(this, _server.ConnectionName, "MacroStep"));

        this.MdiParent = oMDIParent;
        this.WindowState = FormWindowState.Maximized;
        this.Show();

        txtName.Focus();
        txtName.SelectionStart = 0;
        txtName.SelectionLength = txtName.Text.Length;

        tcForm.SelectedTab = tcForm.TabPages["tabDesign"];

        return true;
    }
    catch (Exception ex)
    {
        _g.Errs.Raise(ex);
        return false;
    }
}

即使代码强制窗体为 WindowState.Normal,它仍以最大化打开。我错过了什么?

编辑:我已经在下面的“如何避免屏幕弹跳”链接中进行了建议的更改。我现在有一个不同的、奇怪的症状,并在这里制作了另一个视频:https ://youtu.be/MQENr4pNonA

简而言之,MDI 子项似乎打开了某种最大化,但没有占用 MDI 父项中的整个可用区域。

编辑 2:添加了上面的调用代码。

标签: c#winformsmdimdichildmdiparent

解决方案


推荐阅读