Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27184

VS 2010 Finding a dynamically created form by its "tag" value?

$
0
0
Hey guys,

I've got a little project that requires me to dynamically create a new instance of an existing form (along with all the controls inside that form) when a specific button is clicked. That part's easy enough...

Code:

Dim NewForm As New ExistingForm
Several new instances of the existing form will be created at run-time, so I need a way to access each new form (and all of its child controls) individually in order to manipulate the controls in each form separately. So right after I dynamically create the new form, I assign that form's "tag" value the same as the value of a texbox...

Code:

NewForm.Tag = TextBox1.Text
So later on in another subroutine, I need a way to access whichever dynamically created form has the "tag" value that is equal to the value of TextBox1.Text. For example (the following code doesn't work, obviously, but you should be able to figure out what I'm trying to do)...

Code:

For Each DynamicallyCreatedForm As Form In (All Forms)
    If DynamicallyCreatedForm.Tag = TextBox1.Text Then
        ' Do stuff for the desired form here
    EndIf
Next

How can I accomplish this? Or is there a better way to go about this?

BTW, am using WinForms and targeting the .NET 2.0 framework.

Viewing all articles
Browse latest Browse all 27184

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>