473,324 Members | 2,356 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,324 software developers and data experts.

Referring to main form from nested controls?

The design of my app is such that I have a main form which loads a
variety of user controls. Sometimes these controls will contain their
own constituent sub-controls.

The main form should respond to changes in the constituent controls,
either by showing/hiding menus, or updating status bar text.

Currently I'm rippling up events through the usercontrols back to the
main form. This is proving more and more cumbersome. In VB6, I could
refer to another form directly, but since the main form is
instantiated under vb.net it's not necessarily visible to the
sub-controls in any obvious way.

Does anyone have a strategy for calling a procedure in another form?
Where is the reference to my main form? I'd like to be able to either
call a global routine which fires off a routine in the main form, or
refer to the main form directly.

Thanks

Brian Link, Minnesota Countertenor
----------------------------------
"There are things that we know, and then there are known
unknowns. That is to say, there are things that we now
know that we don't know. But there are also unknown unknowns.
There are things we do not know we don't know."
- U.S. War Secretary, 2003
Nov 20 '05 #1
5 3432
* Brian Link <bl***@visi.com> scripsit:
The design of my app is such that I have a main form which loads a
variety of user controls. Sometimes these controls will contain their
own constituent sub-controls.

The main form should respond to changes in the constituent controls,
either by showing/hiding menus, or updating status bar text.

Currently I'm rippling up events through the usercontrols back to the
main form. This is proving more and more cumbersome. In VB6, I could
refer to another form directly, but since the main form is
instantiated under vb.net it's not necessarily visible to the
sub-controls in any obvious way.


You can call the control's 'FindForm' method.

--
Herfried K. Wagner [MVP]
<http://dotnet.mvps.org/>
Nov 20 '05 #2
On 02 Mar 2004 09:21:10 +0100, hi***************@gmx.at (Herfried K.
Wagner [MVP]) wrote:
* Brian Link <bl***@visi.com> scripsit:
The design of my app is such that I have a main form which loads a
variety of user controls. Sometimes these controls will contain their
own constituent sub-controls.

The main form should respond to changes in the constituent controls,
either by showing/hiding menus, or updating status bar text.

Currently I'm rippling up events through the usercontrols back to the
main form. This is proving more and more cumbersome. In VB6, I could
refer to another form directly, but since the main form is
instantiated under vb.net it's not necessarily visible to the
sub-controls in any obvious way.


You can call the control's 'FindForm' method.


Hm. That would require that the control knew how nested it was. This
is not always the case - sometimes the control is seated on the form,
sometimes on another control on the form, sometimes on a dialog.

Plus then you start getting into the
MyControl.FindForm.Findorm.FindForm.FindForm.MySub () type syntax.

Doesn't the Application keep a reference to the main form instance?

Brian Link, Minnesota Countertenor
----------------------------------
"There are things that we know, and then there are known
unknowns. That is to say, there are things that we now
know that we don't know. But there are also unknown unknowns.
There are things we do not know we don't know."
- U.S. War Secretary, 2003
Nov 20 '05 #3
Hi,

Thanks for posting in the community.

I think we can use the FindForm to retrieve the form where the control on
even if the control is on another control.
e.g. button1 on tabpage, tabpage on usercontrol, and usercontrol on form.
the button1.findform will return the form.

From the MSDN,
Retrieves the form that the control is on.
Control.FindForm Method
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemwindowsformscontrolclassfindformtopic.a sp

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #4
On Wed, 03 Mar 2004 03:20:38 GMT, v-******@online.microsoft.com (Peter
Huang) wrote:
Hi,

Thanks for posting in the community.

I think we can use the FindForm to retrieve the form where the control on
even if the control is on another control.
e.g. button1 on tabpage, tabpage on usercontrol, and usercontrol on form.
the button1.findform will return the form.

From the MSDN,
Retrieves the form that the control is on.
Control.FindForm Method
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemwindowsformscontrolclassfindformtopic. asp

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.


Eureka!

That's it. Thanks a lot!

Brian Link, Minnesota Countertenor
----------------------------------
"There are things that we know, and then there are known
unknowns. That is to say, there are things that we now
know that we don't know. But there are also unknown unknowns.
There are things we do not know we don't know."
- U.S. War Secretary, 2003
Nov 20 '05 #5
* v-******@online.microsoft.com (Peter Huang) scripsit:
I think we can use the FindForm to retrieve the form where the control on
even if the control is on another control.
e.g. button1 on tabpage, tabpage on usercontrol, and usercontrol on form.
the button1.findform will return the form.


Little addition:

This information can be easily found by typing 'FindForm' in the text
editor of VS.NET, setting the caret on it and pressing the F1 key.

--
Herfried K. Wagner [MVP]
<http://dotnet.mvps.org/>
Nov 20 '05 #6

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

Similar topics

4
by: MLH | last post by:
Somehow, I seem to be able to refer to combo-box controls in 2 distinctly different ways. A combo-box on an Access 97 form named TagCountyChooserBox seems can be referenced these ways... ...
21
by: Mark Rae | last post by:
Hi, Apologies if this is a stupid question - I'm a C# newbie... :-) I have a Windows app with two form: frmConfigReg and frmNewApp. frmConfigReg is the startup form. It has several controls,...
4
by: Charles Law | last post by:
Hi guys. I have two threads: a main thread and a background thread. Lots of stuff happens in the background thread that means I have to update several (lots) of controls on a form. It is...
20
by: Robert | last post by:
Need some help to stop me going around in circles on this one.... Have a nested subform (subform2) which simulates a continuous form for the record on the parent subform. Subform2 has rows of...
4
by: Alex Maghen | last post by:
I have a master page which contains a general page framework and also contains a <form runat=server> around most of the content of the page. Inside that <form> tag is a ContentPlaceholder. I...
2
by: Jerry Spence1 | last post by:
One way of passing data to a thread is to encapsulate the thread inside a class. However, I can't refer to my main form objects from within the class/thread as it says "Reference to a non-shared...
2
by: Sugan | last post by:
Hi all, I'm converting a VB 6 exe project to a VB 2005 project. One main functionality in VB 6 that gives errors in VB 2005 project is as follows: In VB6, i have a initial form called...
6
NeoPa
by: NeoPa | last post by:
Introduction The first thing to understand about Sub-Forms is that, to add a form onto another form takes a special Subform control. This Subform control acts as a container for the form that you...
2
kcdoell
by: kcdoell | last post by:
Hello: I have read various posts on this subject but still can not get mine to work. Basically I have a Main form (Forecastform) with a subform (Forecast_Subform). In the footer of the subform I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.