Re: Windows Form Designer generated code

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



in which .vb file. form1.vb or form1.designer.vb?



Martin wrote:
Hi CJ,

in 2005 if you type 'Public Sub New' in the .vb file and press return the editor will auto-generate the code:-

Public Sub New()

' This call is required by the Windows Form Designer.
InitializeComponent()

' Add any initialization after the InitializeComponent() call.

End Sub

You can add your code after the 'Add any....' comment

HTH




"cj" <cj@xxxxxxxxxxxxx> wrote in message news:u5WmI4lNHHA.2028@xxxxxxxxxxxxxxxxxxxxxxx
In a project done in 2003 about a year ago I was told to add the SocketWrench code below into the Windows Form Designer generated code area as shown below.

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

socket = New SocketWrenchCtl.SocketWrench
If socket.Initialize("ELMO") <> 0 Then
Throw New System.Exception("Unable to initialize control")
End If

End Sub

I'm completing a 2005 program now that was so similar I copied many parts of the old 2003 program but I'm not sure what to do with this code. I know 2005 keeps the Windows Form Designer generated code somewhere but I really don't want to add it there unless it is really necessary. Apparently it can go in Form1_Load but I'm not sure that's appropriate. Where should I put it in 2005? Pros and cons?


.



Relevant Pages

  • Re: Windows Form Designer generated code
    ... I guess the Public Sub New is while the form is being instigated and Form1_load is after? ... This seems to be initializing some kind of control, ... It will put in the InitializeComponent for you (if it doesn't, ... SocketWrench code below into the Windows Form Designer generated code area as shown below. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Windows Form Designer generated code
    ... I probably should know but why would it matter if I had my code in Form1_Load instead of Public Sub New? ... socket = New SocketWrenchCtl.SocketWrench ... It will put in the InitializeComponent for you (if it doesn't, ... SocketWrench code below into the Windows Form Designer generated code area as shown below. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Windows Form Designer generated code
    ... This seems to be initializing some kind of control, ... Form1_Load instead of Public Sub New? ... It will put in the InitializeComponent for you (if it doesn't, ... ' This call is required by the Windows Form Designer. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Windows Form Designer generated code
    ... It will put in the InitializeComponent for you (if it doesn't, ... Public Sub New ... ' This call is required by the Windows Form Designer. ... SocketWrench code below into the Windows Form Designer generated ...
    (microsoft.public.dotnet.languages.vb)
  • Windows Form Designer generated code
    ... In a project done in 2003 about a year ago I was told to add the SocketWrench code below into the Windows Form Designer generated code area as shown below. ... Public Sub New ... 'Add any initialization after the InitializeComponent() call ...
    (microsoft.public.dotnet.languages.vb)