Results 1 to 3 of 3

Thread: [RESOLVED] Identifing a instance of a multiple form

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2013
    Posts
    66

    Resolved [RESOLVED] Identifing a instance of a multiple form

    Hello.

    I have created 5 instances of the same form and add them to a panel.

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

    For i = 1 to 5

    Dim form2 As New Form2()

    form2.TopLevel = False

    Me.Panel1.Controls.Add(form2)

    form2.Show()
    Next i

    End Sub


    The Question is if i want to move one of the forms to another panel how do i identify a particular form in the panel (that is they are all named form2).

    Thank you.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,038

    Re: Identifing a instance of a multiple form

    Well, they'd be in the Controls collection in the order that you added them, but I wouldn't rely on that, since they could be anywhere in that Controls collection (though they'd probably be items 0-4, unless there are other controls on the panel). What I'd do is have either a List(of Form2) and add them to that as well as to the Controls collection, or if you wanted to be able to identify them by some means other than index, then use a Dictionary (of someUsefulType, Form2), where someUsefulType is whatever you want to use to identify them, whether a string, a number, or something more exotic.

    I guess I should add that, if you used the Dictionary, then whatever you set as the key for the form you could also add to the .Tag property of the form such that the form would be able to look itself up in the dictionary.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2013
    Posts
    66

    Re: Identifing a instance of a multiple form

    Thank u i have done some more reading on Controls collectin. getting the hang of it.

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width