Accessing controls on another form.

D

DaveG

Hi

I posted this to the .Net general newsgroup and got a reply from "Morten"
who has given me an answer but in C# a language I have never worked with.
VB.Net is still very new to me, I was hoping someone here in the VB.net
group could help me a little. I have copied the posts to here.

Morten has given me a code snippet in C# but where do I use it and what is
the VB.Net equivalent.

Thanks DaveG

''''''''' Orig Post ''''''''''''''
Thanks Morten

Now the problem is I have used the overload in normal funtions and subs
but never with the constructors, so now I'm a little lost, I understand
the reasons for the overload..... so the New form2(Me) will be excepted
bur how to implement it is where I am stuck......


Dave, overloading a constructor is done the exact same way, although I'm
not sure how the VB syntax is. Store the Form1 reference for later use.

private Form1 myParent;

public Form2(Form1 f)
{
myParent = f;
}

then simply call

myParent.MethodOrSimilarInForm1()

whenever you need.
 
C

Cor Ligthert

Dave,

There are many roads that goes to Rome

Your mainform
\\\
Dim frm As New Form2
frm.Owner = Me
frm.Show()
///
You form where you want to use it.
\\\
MessageBox.Show(DirectCast(Me.Owner, Form1).TextBox1.Text)
///
Assuming that you have a textbox1 on form1

I hope this helps,

Cor
 
H

Herfried K. Wagner [MVP]

DaveG said:
I posted this to the .Net general newsgroup and got a reply from "Morten"
who has given me an answer but in C# a language I have never worked with.
VB.Net is still very new to me, I was hoping someone here in the VB.net
group could help me a little. I have copied the posts to here.

Depending on the situation direct access to the parent form isn't required
in order to update the parent form upon closing the other form:

<URL:http://groups.google.de/groups?selm=#[email protected]>

In MDI environments:

\\\
DirectCast(Me.MdiParent, MainForm).TextBox1.Text = ...
///

Providing a reference to an application's main form
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=accessmainform&lang=en>

In VB 2005 you can access form instances more easily with 'My.Forms.*'.
 
D

DaveG

Thanks guys for your quick responses.

I think I am crawling along one of these roads to Rome. now I can see how
I am supposed to implement a basic setup I'm sure I can play a little, if
not "I shall be back".

DaveG
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top