OK, I like this solution, however.....I am having an issue executing it.
1. I defined this:
Public Interface PrintChildForm
Sub PrintMe()
End Interface
2. I modified my form like this:
Public Class ProfileEdit
Inherits System.Windows.Forms.Form
Implements PrintChildForm
3. And I changed my sub as follows:
Public Sub PrintMe() Implements PrintChildForm.PrintMe
However....when I try to call it in the MDI like this:
Dim x As PrintChildForm = DirectCast(Me.ActivateMdiChild,
PrintChildForm)
I get a compile error on "Me.ActivateMdiChild" that says
Argument not specified for parameter 'form' of 'Protected Sub
ActivateMdiChild(form As System.Windows.Forms.Form)'.
I have no idea what parameter it's looking for.
"Herfried K. Wagner [MVP]" wrote:
"EdB" <Ed*@discussions.microsoft.com> schrieb:I have an MDI form with similar child edit forms. The child Edit forms
have
public methods that of consistent names. I have a tool bar that calls
these
methods. Here's how I'm doing it now (toolbar click event).
1) Dim f As Object
2) Select Case Trim$(ActiveMdiChild.Text)
3) f = CType(ActiveMdiChild, <Hard Coded Valid Form Object Based On Case>)
4) f.<Public Method>
Now, I know that I could use an inherited form, but for a number of
reasons,
I am trying to stay awau from that. I was hoping to extract the type from
ACTIVEMDICHILD and use that in my CType statement to eliminate the Select
Cases, but I can not find a Syntax that works.
Instead of inheriting from a common base class that provides the method,
consider writing an interface which is implemented by the child form
classes:
\\\
Public Interface ISaveable
Sub Save
End Interface
..
..
..
Public Class ChildForm1
Inherits Form
Implements ISaveable
.
.
.
Public Sub Save() Implements ISaveable.Save
...
End Sub
End Class
..
..
..
Dim f As ISaveable = DirectCast(Me.ActiveMdiChild, ISaveable)
f.Save()
///
If you don't like this solution, take a look at 'CallByName':
Calling a method by its name
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=callbyname&lang=en>
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>