Overloading new()

  • Thread starter Thread starter jamie
  • Start date Start date
J

jamie

Why can I not overload new() for a form?

Maybe I am trying to do it wrong.?

jamie
 
You can overload New for a form by adding another method named 'New' with
different parameters than the original:

--Code starts--
Public Sub New()
MyBase.New()

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

'Add any initialization after the InitializeComponent() call

End Sub

Public Sub New(ByVal strMessage As String)
Me.New()

' Add any additional code here


End Sub

--Code Ends--


You should only use the Overloads keyword if you are overloading an
inherited method.

Remember to make sure your new 'New' method calls MyBase.New and
InitializeComponent otherwise the form will not load correctly.

Hope this helps.
 
* "jamie said:
Why can I not overload new() for a form?

Maybe I am trying to do it wrong.?

\\\
Public Sub New()
...
End Sub

Public Sub New(ByVal UserName As String)
MyBase.New()
...
End Sub
///

What's the problem?
 
Oh....
Well...
You dont have to make it that simple. :P
That takes all the fun away.

Thanks
jamie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top