Home All Groups Group Topic Archive Search About

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

Author
27 Jun 2005 12:08 AM
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

Author
27 Jun 2005 1:44 AM
Dennis
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


--
Dennis in Houston


Show quoteHide quote
"Tom" wrote:

> 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
>
Author
27 Jun 2005 3:08 AM
Dennis
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

--
Dennis in Houston


Show quoteHide quote
"Tom" wrote:

> 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
>