Re: Form Reference Question (Getting Back Your Visual Basic 6.0 Goodies)



gerryLowry::Ability Business Computer Services {KCAZ0H1} wrote:
"Getting Back Your Visual Basic 6.0 Goodies" by Billy Hollis, 2003-5-14, states:

"Getting a Forms Collection
Visual Basic 6.0 developers are often fond of looping through the currently loaded forms in an application to find out something, such as if a particular form it loaded, or how many of a particular type of form are loaded. Windows Forms does not include a Forms collection, however, so gaining such functionality in Visual Basic .NET means some additional work."


Hollis gives an example were we have "Form1" and "Form2".

Form1 has TWO buttons ... the first button creates a number of instances of Form2;
the second button uses a collection to make each instance of Form2 invisible.


PROBLEM

The above is like a FORWARD reference ... from the main form, to some other form.

I am struggling with reversing the syntax ...

from other forms and other modules I would like to control Form1 ....
for example, when the end user clicks my control [some button] on Form2
which starts a routine myModuleCode, it would be nice if, in myModuleCode,
I could do something like:

....
"Form1".Visible = False ' Hide Form1 until processing is complete
.... ' start of processing
....
....
.... ' end of processing
"Form1".Visible = True ' Unhide Form1 because processing is complete
....


My feeble attempts to adapt Hollis' example has only succeeded in causing a variety of crashes. Using "Me", "Me.Name", et cetera, did not help me discover the correct syntax.

Needless to say, the online help was useless (or perhaps it is I who is useless at locating information just beyond my fingertips).

Rather than continuing to bang my brain against the syntax wall, I hope some reader of this newsgroup will be kind enough to share her/his expertise in this matter.

Thank you .... regards, gerry



As long as myModuleCode has a reference to "Form1" then you can do this. You'll probably have to send in a reference to form1 to form2. Something like:


public class form2
	dim RefToForm1 as Form1
	sub new(F1 as Form1)
		mybase.new()
		RefToForm1 = F1
	end sub
	sub myModuleCode()
		RefToForm1.Visible = False
		.....
		RefToForm1.Visible = False
	end sub
End class

note that this way of doing it causes you to create Form2 this way:

From inside Form1 somewhere...
dim F2 as new Form2(Me) 'This passes in the reference of form1 to form2

Hope it helps
Chris
.


Loading