Forms - Editing Form text boxes from a class

All,

Vb.Net 2005.

Say i have 2 forms that both have a textbox called textbox1, how can i set to update this from a different class.

i was expecting something like .........

' Call from either for1 or form 2
editTheBox(me)

then in the different class ....

sub editTheBox(ByVal frm as windows.Forms.Form)

frm.TextBox1.text = "hello"

end sub

This (in hindsight) obviously did not work because it did not know what form to reference, and i became aware that the only way i could get this to work was to use something like .....

sub editTheBox(ByVal frm as Frm1)

frm.TextBox1.text = "hello"

end sub

The problem is this only works for form1 now, but i wanted it to be generic to work for form1 and form 2. (In the real app this will be referenced by 3 forms if i can get it working).

Any ideas, anyone ?

Thanks,

Daz



yo_daz_ukAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Carl TawnSystems and Integration DeveloperCommented:
How about something like:

    Public Shared Sub UpdateTextbox(ByVal frm As System.Windows.Forms.Form)

        Dim ctl() As System.Windows.Forms.Control
        ctl = frm.Controls.Find("TextBox1", True)

        If ctl.Length = 1 Then
            If TypeOf ctl(0) Is TextBox Then
                CType(ctl(0), TextBox).Text = "Hello world"
            End If
        End If

    End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
yo_daz_ukAuthor Commented:
Thats great cheers!!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.