By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,219 Members | 2,140 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,219 IT Pros & Developers. It's quick & easy.

Overloading new()

P: n/a

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

Maybe I am trying to do it wrong.?

jamie
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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" <an*******@discussions.microsoft.com> wrote in message
news:ce****************************@phx.gbl...

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

Maybe I am trying to do it wrong.?

jamie

Nov 21 '05 #2

P: n/a
* "jamie" <an*******@discussions.microsoft.com> scripsit:
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?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #3

P: n/a
Oh....
Well...
You dont have to make it that simple. :P
That takes all the fun away.

Thanks
jamie
-----Original Message-----
You can overload New for a form by adding another method named 'New' withdifferent 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 aninherited method.

Remember to make sure your new 'New' method calls MyBase.New andInitializeComponent otherwise the form will not load correctly.
Hope this helps.
"jamie" <an*******@discussions.microsoft.com> wrote in messagenews:ce****************************@phx.gbl...

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

Maybe I am trying to do it wrong.?

jamie

.

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.