如何停止InitializeComponent更改表单设计器代码?

时间:2017-10-25 16:13:50

标签: c# visual-studio windows-forms-designer

我有一个覆盖方法,我在InitializeComponent中调用。

public class ComponentResourceManager2 : System.ComponentModel.ComponentResourceManager

我的问题是,每次我在DesignerForm中更改某些内容时,方法InitializeComponent都会更改,以便该方法使用系统一

System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager();

Ex:我需要这个

    private void InitializeComponent()
    {
        ComponentResourceManager2 resources = new ComponentResourceManager2(typeof(Form1));
        this.directDrawViewer1 = new MyOwn.Imaging.Components.DirectDrawViewer();
        this.speedButton1 = new MyOwn.Components.SpeedButton();
        ...

但每当我改变某些东西时,它又会再次出现:

    private void InitializeComponent()
    {
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
        this.directDrawViewer1 = new MyOwn.Imaging.Components.DirectDrawViewer();
        this.speedButton1 = new MyOwn.Components.SpeedButton();

如何使我的方法成为InitializeComponent使用的方法,而不是每次更改内容时都重置?

1 个答案:

答案 0 :(得分:1)

您不应该更改设计器代码,在调用InitializeComponent()之后,在Form的构造函数中设置您在InitializeComponent中设置的内容。每次更改设计器中的内容时,Visual Studio都会重新生成设计器文件