Resolved editing designer code

aaaron

Well-known member
Joined
Jan 23, 2011
Messages
219
Programming Experience
10+
Something funny is going on now. This is old code that used the older menuitem version. I had to make many changes in the designer code to update to TooStrip. I guess I got the designer angry because every time I use it, it changes some of the code to one or two steps back. I deleted vs, obj, bin and the cache in C:\Users\Cal\AppData\Local\Microsoft\VisualStudio\16.0_5845da30. But it still reverts when it is giving the opportunity.

Can a thread have more than on solution?
 
Last edited by a moderator:
You really ought to avoid editing the designer code by hand if at all possible. If you needed to replace a MainMenu with a MenuStrip then that should have all been done visually, not manually.
 
You really ought to avoid editing the designer code by hand if at all possible. If you needed to replace a MainMenu with a MenuStrip then that should have all been done visually, not manually.
I can see that now.

If a Form needs a special New with parameters should I put it in *.vb or in *.Designer.vb.

Do I also need a New()?

I had been putting it in the latter.
 
I can see that now.

If a Form needs a special New with parameters should I put it in *.vb or in *.Designer.vb.

Do I also need a New()?

I had been putting it in the latter.
All classes have a default constructor that the system adds implicitly. If you want to add functionality in a constructor and/or one or more constructors with different signatures then you should add them yourself in the user code file. Never touch the designer code file unless you expressly need to to fix a system glitch.

If you want to add a parameterless constructor then just type public sub new and hit Enter. The system will automatically generate the following code:
VB.NET:
Public Sub New()

    ' This call is required by the designer.
    InitializeComponent()

    ' Add any initialization after the InitializeComponent() call.

End Sub
You then add your initialisation code where indicated.

Note that every constructor must make a call to that InitializeComponent method as that is where your designed controls get created and configured. If you only want a constructor with parameters then do as above and then add your parameter(s). If you want multiple constructors then have them call each other where possible and then call InitializeComponent in those at the bottom of the ladder, e.g.
VB.NET:
Public Sub New()
    InitializeComponent()
End Sub

Public Sub New(data As String)
    Me.New()

    'Use data here.
End Sub
 
Split to new thread. (one topic per thread please)
 
If a Form needs a special New with parameters should I put it in *.vb or in *.Designer.vb.
You should never (rarely) modify .Designer.vb files manually.

1617277404416.png
 

Latest posts

Back
Top