473,386 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

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
Nov 21 '05 #1
2 4692
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
"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

Nov 21 '05 #2
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
"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

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: DraguVaso | last post by:
Hi, I'm having some weird behaviour, and I can't find any solution to this. I made a UserControl (uclCommands) which contains a Toolbar (ToolBar1) with Modifiers = Public. I put this...
4
by: Dennis Burdett | last post by:
I have a pretty complex control which use to be a C# windows form that I am trying to make into a control that can be dragged onto a VB6 form. I was able to make it into a com class that I could...
1
by: jralford | last post by:
Hi, Another question from a C# newbie: I have a usercontrol class that includes a customized control. Now, if I create an instance of the class, and click on it, a click event is raised for the...
5
by: Mark Friedman | last post by:
Does anyone know how to reference a subcontrol of a UserControl within client-side script. For example, if I have a TextBox as one of the elements of my UserControl with an id of "MyTextBox", how...
2
by: Eric Maia | last post by:
I have two UserControls I am using in a form. These are each also used separately in two other forms. The structure is essentially this: CourseUserControl.ascx - select or enter a course...
9
by: Richard Brown | last post by:
Can anyone give me a good argument one way or another? I have an 'address' set of fields that are used in various situations (a client has an address, a destination has an address, etc). These...
0
by: Matthew | last post by:
All, I have searched google and the newsgroups but can't find anything the same as what I am experiencing (though I may have missed something). I have controls (textboxes) within UserControls...
12
by: Joe | last post by:
Hello All: Do I have to use the LoadControl method of the Page to load a UserControl? I have a class which contains three methods (one public and two private). The class acts as a control...
4
by: Sam Martin | last post by:
Hi, I have got a User Control that contains for the sake of argument, a single DataList control. eg. <asp:DataList id="DataListMain" runat="server" RepeatDirection="Horizontal"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.