Rafael
Rafael

Reputation: 45

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?

Upvotes: 2

Views: 1253

Answers (1)

subkonstrukt
subkonstrukt

Reputation: 446

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

Upvotes: 2

Related Questions