Link to home
Start Free TrialLog in
Avatar of ExpertsAL
ExpertsAL

asked on

Finding a form object from a name in a string.

This is a vb.net question.

I have a few Labels in my form and if anyone of these Labes change I want to change an associated Label.

Like this:

label one
label onep
label two
label twop
label three
label threep

Then I have a function that handels the change of label one, two and three. In this function I do:

Dim ctrlToChange As String = sender.Name & "p"

and now I wish to get the object onep or twop or threep from the name I have stored in ctrlToChange.

How to do?

Thank you.

Anders Liden
Coder
www.dvdnorden.se

Avatar of JR2003
JR2003

I think you may be better off using control arrays for this one.
I don't believe that VB.NET does control arrays, but I'm not sure.

This is the VB area. There is a separate one for VB.NET. You might stand a better chance there.


Incidentally in VB, you can address Form controls by their names:

Form1.Controls("Label1").Caption = "New Caption"
In VB.NET:

  Public Function OpenForm(ByVal FormName As String) As Form

    Dim oForm As Form = CType(Activator.CreateInstance(Type.GetType(FormName, True, True)), Form)
    oForm.StartPosition = FormStartPosition.CenterScreen
    oForm.Show()

    Return oForm

  End Function

Bob
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Why a grade of C ExpertsAL?

Idle_Mind