Better way to set the status of a Form's controls from another form.

ajeeshco

Well-known member
Joined
Sep 19, 2006
Messages
257
Location
Cochin, India
Programming Experience
3-5
Hi,
In my Application I would like to set the status of a Form's controls using another Form. For that, what I'm doing now is passing the reference of the FirstForm to the SecondForm during the creation of the SecondForm as follows
Dim secondForm As SecondForm = New SecondForm(Me)

and I could set the status of the controls of the FirstForm.

I would like to know whether there is any other way (better way) to do the same. Is this something related with design patterns then plz:) send me links for reference.

Thx in Advance
 
Can you say which is better?

Hi,
Thanks for sending the link. Can you plz say which one is better? In my point of view I think using Events is better. Am I right? Plz help me.
 
If you pass a reference to the first form when you create the second form then the second form can access any public members of the first form. This isn't really necessary so from the point of view of keeping the scope of everything as narrow as possible the first form handling an event of the second form is preferable. It is more hassle though so it really depends how important it is to you to be as correct as possible.
 
Try this

Try creating a module and add some values which you can set before the form loads, and on the second forms load event you could use these values for setting the right properties of the desired controls...
 
Using a module will work but it is often used because of laziness when there are better or more appropriate ways to do it. You could simply declare everything in a module but we don't. Generally you should keep scopes as narrow as possible. If you genuinely need access to an object throughout your app then a module is appropriate. if you only need access to it in two forms, one of which creates the other, then using a module is almost certainly not appropriate.
 
Back
Top