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
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
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.
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").C aption = "New Caption"
Form1.Controls("Label1").C
In VB.NET:
Public Function OpenForm(ByVal FormName As String) As Form
Dim oForm As Form = CType(Activator.CreateInst ance(Type. GetType(Fo rmName, True, True)), Form)
oForm.StartPosition = FormStartPosition.CenterSc reen
oForm.Show()
Return oForm
End Function
Bob
Public Function OpenForm(ByVal FormName As String) As Form
Dim oForm As Form = CType(Activator.CreateInst
oForm.StartPosition = FormStartPosition.CenterSc
oForm.Show()
Return oForm
End Function
Bob
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Why a grade of C ExpertsAL?
Idle_Mind
Idle_Mind