如何避免这种影响=>表单边框没有,但在加载时仍然可见



我正在父表单中打开子表单,并且我已将formborder style设置为无,但是在为I can see its border for fraction of second打开子窗体时,我如何避免这种情况,我尝试了下面的代码,但它并没有使这种效果消失,我如何避免这种效果并顺利加载表单,我试图分配form opacity = 0并设置计时器来应用fade-in效果,但这也不能解决我的问题,请以正确的方式指导我

我试图避免此问题的代码

int originalExStyle = -1;
        bool enableFormLevelDoubleBuffering = true;
        protected override CreateParams CreateParams
        {
            get
            {
                if (originalExStyle == -1)
                    originalExStyle = base.CreateParams.ExStyle;
                CreateParams cp = base.CreateParams;
                if (enableFormLevelDoubleBuffering)
                    cp.ExStyle |= 0x02000000;   // WS_EX_COMPOSITED
                else
                    cp.ExStyle = originalExStyle;
                return cp;
            }
        }

LarsTech的评论是可能的核心问题,MDI子表单必须具有相当大的边框。 Winforms忘记强制执行是一项要求,运行时事故多种多样,没有解决方法。 否则也可以解释为什么不透明度不起作用,它只能在顶级窗口上工作。

originalExStyle 的使用在根本上也是错误的,base.CreateParams并不总是返回相同的值。当程序分配间接影响 ExStyle 值的窗体的某些属性时,它会更改。 包括 Form.MdiParent,它设置WS_EX_MDICHILD样式标志。 您需要将其删除并仅使用 cp . 嘎�� 将其更改为:

    protected override CreateParams CreateParams
    {
        get
        {
            CreateParams cp = base.CreateParams;
            if (enableFormLevelDoubleBuffering)
                cp.ExStyle |= 0x02000000;   // WS_EX_COMPOSITED
            return cp;
        }
    }

最新更新