Results 1 to 3 of 3

Thread: control over a dynamically created form

  1. #1
    Jas91 is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Jul 2012
    Location
    Baghdad, Italy. OK?=
    Posts
    17
    Reputation
    13

    control over a dynamically created form

    hi guys!

    I have a method in Form1 which creates instances of Form2 and shows them:
    Dim f As New Form2
    f.Show()

    now I have to use public methods which are declared in Form2, from Form1...I actually tryed this, but didn't work

    (I'm on a different method in Form1 now)

    For Each frm as Form2 in Application.OpenForms
    frm.MyFunction
    Next

    any idea?

  2. #2
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,200
    Reputation
    2369
    You're using .Net 4 so you can use the OfType collection filter method:
    For Each frm In Application.OpenForms.OfType(Of Form2)()

    The type of frm loop variable is here inferred from the Of T argument, which here is Form2, so the 'As Form2' is not necessary.

    Traditionally you would have to use a common type in loop, for example Form, and check the type of object using TypeOf operator, and cast the object to specific type using DirectCast/CType. I mention this because you should know and likely will encounter situations where that is needed later.

  3. #3
    Jas91 is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Jul 2012
    Location
    Baghdad, Italy. OK?=
    Posts
    17
    Reputation
    13
    ewwwww thanksssssss!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking