Calling UserControl from within a form in the control...

T

Tom

Let's say I have written a VB.NET user control, with the following
components:

MyControl.sln
MyUserControl.vb (user control)
Form1 (Windows Form)
Form2 (Windows Form)

Now, lets say that within the MyUserControl I have a public function
that can be called, and that function causes the Form1 form to load in
Modal mode (ShowDialog). Now, within that form I need to be able to
access the data properties (public functions, properties, etc) from the
MyUserControl that called it (not just another instantiation, but the
actual one that loaded Form1 in the first place). The first question
is: How can I do this? I.E. How can Form1 access the data in the
MyUserControl? Yea, I could create a New constructor (or a bunch of
properties) and pass the data back and forth that way, but I really
need to be able to access the entire component (MyUserControl) that
called/created Form1. There must be a base method or something that I
can use to get back to MyUserControl but I'm having a brain fart and am
unable to figure this out.

Also, for the second question: Let's say MyUserControl also has another
public function that loads Form2 (in modal mode). On Form2, I need to
put another, new copy (visual) of MyUserControl. I'm not sure this
would work, since Form2 is already a part of MyUserControl (i.e. how
would this compile properly?)

Any advice on these two questions would be greatly appreciated. Thanks
in advance.

Tom
 
G

Guest

In Form1 and Form2, define a field

Public ReadOnly myorigcontrol() as Control

Then, before the form is shown;

Form1.myorigcontrol = me
Form1.Show

Then in Form1
myvar = directcast(myorigcontrol, MyUserControl).myproperty
 
G

Guest

Or directly define it:

Public myorigcontrol() as MyUserControl
Then, before the form is shown;

Form1.myorigcontrol = me
Form1.Show

Then in Form1
myvar = myorigcontrol.myproperty
myorigcontrol.myproperty = myvar
 

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