覆盖不触发 4.5 框架的加载

本文关键字:框架 加载 覆盖 | 更新日期: 2023-09-27 18:36:50

我正在MDI控件上使用Winforms项目。 我只是花了一些时间将框架从 2.0 移动到 4.5。 我知道我会遇到一些问题,但这个我没有看到

我没有得到一个经常用于触发的简单覆盖"OnLoad"事件。 然而,它们在2.0版本中被解雇。 我用谷歌搜索了一段时间,看不出任何理由。

下面是一些要查看的代码:

public partial class MDIParent1 : Form
{
    public void InitializeComponent()
    {
        System.ComponentModel.ComponentResourceManager(typeof(MDIParent1));
        // 
        // MDIParent1
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.BackColor = System.Drawing.Color.WhiteSmoke;
        this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
        this.ClientSize = new System.Drawing.Size(1133, 223);
        this.Controls.Add(this.IconStrip_1);
        this.Controls.Add(this.pnlThumbnails);
        this.Controls.Add(this.statusStrip);
        this.Cursor = System.Windows.Forms.Cursors.Default;
        this.ForeColor = System.Drawing.SystemColors.WindowText;
        this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
        this.IsMdiContainer = true;
        this.KeyPreview = true;
        this.Location = new System.Drawing.Point(20, 20);
        this.Menu = this.mainMenu1;
        this.Name = "MDIParent1";
        this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
        this.Text = "Youll never know what this actually said";
        this.TransparencyKey = System.Drawing.Color.Yellow;
        this.statusStrip.ResumeLayout(false);
        this.statusStrip.PerformLayout();
        this.pnlThumbnails.ResumeLayout(false);
        this.thumbsTableLayoutPanel.ResumeLayout(false);
        this.tabThumbnails.ResumeLayout(false);
        this.IconStrip_1.ResumeLayout(false);
        this.IconStrip_1.PerformLayout();
        this.ResumeLayout(false);
        this.PerformLayout();
    }
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        ...
        //Not Firing! in 4.5?!
    }   
}

剪掉了我认为可以帮助您解决我的问题的内容。 请记住,它在 2.0 中有效,但当我将其提高到 4.5 时就不行了。 它确实构建了,但奇怪的是,它没有触发此事件。 当然,这是一个主要的软件,整个项目中都有类似的事件。

覆盖不触发 4.5 框架的加载

我需要禁用"Just my code",然后听上面评论的"Hans Passant"并寻找"第一次机会异常",它采用FileLoadException的形式。 但真正的问题是,在表单实际加载之前,仍然有对一些 2.0 代码在后台运行的引用。 我暂时解决了这个问题,把它放在 AppConfig 中:<startup useLegacyV2RuntimeActivationPolicy="true">然后我的 OnLoad 开始触发。