Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / September 2004

Tip: Looking for answers? Try searching our database.

Called A Function in Array Of MDI Child Forms

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Daniel Friend - 07 Sep 2004 21:05 GMT
I have a bunch of mdi child forms and I use a collection for which forms are
opened.  I would like to call a public function in the open forms called
ChangeFormat, but I am getting the following error:

'ChangeFormat' is not a member of 'System.Windows.Forms.Form'.

Can somebody tell me how I can achieve this?

Thanks,

Dan

Example Code:
----------------------------------------------------------------------

Public Sub ChangeFormat()
   Try
       Dim frmAny As Form
       For Each frmAny In Forms
           Try
               frmAny.ChangeFormat()
           Catch
           End Try
       Next
   Catch ex As Exception
   End Try
End Sub
Herfried K. Wagner [MVP] - 07 Sep 2004 21:35 GMT
* "Daniel Friend" <dan@donotspam.com> scripsit:
> I have a bunch of mdi child forms and I use a collection for which forms are
> opened.  I would like to call a public function in the open forms called
[quoted text clipped - 8 lines]
>             Try
>                 frmAny.ChangeFormat()

Replace the line above with this:

\\\
DirectCast(frmAny, AnyForm).ChangeFormat()
///

'AnyForm' is the type of your MDI children.

Signature

M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/

Daniel Friend - 07 Sep 2004 22:05 GMT
What if there are about 50 types of MDI children and you don't know which
one for need to change?  I tried the following code to get the type, but I
get an error:
"aType is not defined"

Thanks for your help,

Dan

Public Sub ChangeFormat()
   Try
       Dim frmAny As Form
       For Each frmAny In Forms
           Dim aType As Type
           aType = frmAny.GetType
           Try
               DirectCast(frmAny, aType).GetTheme()
           Catch ex As Exception
           End Try
       Next
   End Try
End Sub

> * "Daniel Friend" <dan@donotspam.com> scripsit:
> > I have a bunch of mdi child forms and I use a collection for which forms are
[quoted text clipped - 17 lines]
>
> 'AnyForm' is the type of your MDI children.
Herfried K. Wagner [MVP] - 07 Sep 2004 22:57 GMT
* "Daniel Friend" <dan@donotspam.com> scripsit:
> What if there are about 50 types of MDI children and you don't know which
> one for need to change?  I tried the following code to get the type, but I
> get an error:
> "aType is not defined"

Create an interface that all MDI child classes implement:

\\\
Public Interface ITheme
   Sub GetTheme()
End Property
///

\\\
Public Class Form2
   Inherits System.Windows.Forms.Form
   Implements ITheme

   Public Sub GetTheme() Implements ITheme.GetTheme
       ...
   End Sub
   .
   .
   .
End Class
///

> Public Sub ChangeFormat()
>     Try
>         Dim frmAny As Form
>         For Each frmAny In Forms

\\\
DirectCast(frmAny, ITheme).GetTheme()
///

>         Next
>     End Try
> End Sub

Signature

M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.