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

Overloads/Shadows question

P: n/a
I'm developing a form which is to be used as an enhanced MessageBox(). I
don't want it to be shown with the default Show() method, so as I provided
overloaded versions of Show() I marked them as Shadows and I didn't provide
a parameterless version of Show(). Would it have been better (or would this
have even worked) to simply make a Private version of Show() and only
exposed (i.e., made Public) the other overloads?
Nov 20 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
If you dont want the default contructor.

Class MyMessageBox
Inherits MessageBox
Public Sub New( your ParameterList )
MyBase.Show( yourParameterList )
End Sub

Or

Class MyMessageBox
Inherits MessageBox
Public Sub New( )
MyBase.Show( yourDefaultParameterList )
End Sub


--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"Jeff Johnson [MVP: VB]" <i.***@enough.spam> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
I'm developing a form which is to be used as an enhanced MessageBox(). I
don't want it to be shown with the default Show() method, so as I provided
overloaded versions of Show() I marked them as Shadows and I didn't provide a parameterless version of Show(). Would it have been better (or would this have even worked) to simply make a Private version of Show() and only
exposed (i.e., made Public) the other overloads?

Nov 20 '05 #2

P: n/a

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:eJ**************@TK2MSFTNGP10.phx.gbl...
If you dont want the default contructor.

Class MyMessageBox
Inherits MessageBox
Public Sub New( your ParameterList )
MyBase.Show( yourParameterList )
End Sub

Or

Class MyMessageBox
Inherits MessageBox
Public Sub New( )
MyBase.Show( yourDefaultParameterList )
End Sub


This isn't a question about constructors but rather about hiding the Show()
method that is inherited from the Form class. I'm not wrappering
MessageBox(). This is a complete replacement based on Form. I should have
mentioned that.
Nov 20 '05 #3

P: n/a
Hi Jeff,

Why do you not use the form.showdialog method which is made for this?

Cor
I'm developing a form which is to be used as an enhanced MessageBox(). I
don't want it to be shown with the default Show() method, so as I provided
overloaded versions of Show() I marked them as Shadows and I didn't provide a parameterless version of Show(). Would it have been better (or would this have even worked) to simply make a Private version of Show() and only
exposed (i.e., made Public) the other overloads?

Nov 20 '05 #4

P: n/a

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:O$**************@tk2msftngp13.phx.gbl...
Why do you not use the form.showdialog method which is made for this?


Because I want this form to be used exactly the way people are used to using
MessageBox(), and that's MessageBox.Show(...). It calls ShowDialog()
internally.
Nov 20 '05 #5

P: n/a
Jeff,
In addition to the other comments.

The "problem" with shadowing the Show method in your derived form is that I
can put an instance of your form in a Form variable and call the Show
method!

Public Class JeffsMessageBoxForm
Inherits Form

...

Public Shadows Sub Show(ByVal requiredParm As String)
End Sub
End Class

Dim frm As Form = New JeffsMessageBoxForm
frm.Show()

I find Shadows to be best used for versioning control. Only.

In the few places where I wanted to do this, I have:
1. Created a normal class that has the Shared Show methods on it (similar to
MessageBox), and the form itself is Private (friend) to the assembly.

Friend Class JeffsMessageBoxForm
Inherits Form

End Class

Public NotInheritable Class JeffsMessageBox

Private Sub New
End Sub

Public Shared Sub Show(ByVal requiredParm As String)
Dim frm As New JeffsMessageBoxForm
frm.Show()
End Sub

End Class

2. Allow the Show to be called, and just make a point not to call it.

If I did decide to use Shadows, I would Shadow both, marking the existing
one Obsolete:

<Obsolete("Use Show(requiredParm)", True)> _
Public Shadows Sub Show()
MyBase.Show()
End Sub

Public Shadows Sub Show(ByVal requiredParm As String)
...
MyBase.Show()
End Sub

Hope this helps
Jay

"Jeff Johnson [MVP: VB]" <i.***@enough.spam> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
I'm developing a form which is to be used as an enhanced MessageBox(). I
don't want it to be shown with the default Show() method, so as I provided
overloaded versions of Show() I marked them as Shadows and I didn't provide a parameterless version of Show(). Would it have been better (or would this have even worked) to simply make a Private version of Show() and only
exposed (i.e., made Public) the other overloads?

Nov 20 '05 #6

P: n/a

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
In the few places where I wanted to do this, I have:
1. Created a normal class that has the Shared Show methods on it (similar to MessageBox), and the form itself is Private (friend) to the assembly.


I like this. I was thinking of going the
all-shared-method-don't-allow-instantiation route anyway. This has convinced
me.

So much to learn....
Nov 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.