On Tue, 11 Nov 2008 00:37:46 -0800,
th*******@gmail.com
<th*******@gmail.comwrote:
Anyone know a consistent object reference to forms controls?
I have 2 forms. The main form instantiates a 2nd form, creates some
text and label objects on the 2nd form, hides itself and then uses the
ShowModal method to show the 2nd form. (so first form is hidden and
modal) (I think it was showmodal...)
But the first form has a list box that I want to reference from the
2nd form. I cannot seem to find a reference to access the controls or
the values of controls on the first form from the 2nd form.
Without a concise-but-complete code sample, it's impossible to say for
sure what would work best for your code. But the basic idea is to do one
of two things:
-- pass a reference to the control of interest to the second form
-- make the member field in the first form public, and pass a
reference to that first form to the second form
The former is preferable. You need to get a reference to _something_ to
the second form in either case, so you might as well just make it the
reference you really need.
An even better solution, though less literally addressing your question,
would be to pass the reference to the first form to the second form, and
have some public property or method on that first form that allows the
second form to manipulate the control without ever actually having direct
access to it.
Pete