简体   繁体   中英

How to stop InitializeComponent changing the form designer code?

I have a override method that i'm calling in the InitializeComponent.

public class ComponentResourceManager2 : System.ComponentModel.ComponentResourceManager

My problem is, every time that i change something in the DesignerForm the method InitializeComponent change so that the method use the system one

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

Ex: I need this

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

But every time that i change something it goes again to this:

    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();

How can i make my method to be the used by the InitializeComponent without being reset every time something is changed?

You shouldn't change the designer code, set things you are setting in InitializeComponent in the constructor of your Form after InitializeComponent() is called. Visual Studio will regenerate the designer file every time you change something in the designer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM