how can i reference controls on one form to enable them from anotehr form?
assuming I'm missing a dim statement someplace or something in the syntax but so far every thing that i've tried i've gotten some form of an error when trying to.
Printable View
how can i reference controls on one form to enable them from anotehr form?
assuming I'm missing a dim statement someplace or something in the syntax but so far every thing that i've tried i've gotten some form of an error when trying to.
UMM you have to have access to the form... you can declare a public variable in a module and set it equal to your form, ieQuote:
Originally posted by ronman1123
how can i reference controls on one form to enable them from anotehr form?
assuming I'm missing a dim statement someplace or something in the syntax but so far every thing that i've tried i've gotten some form of an error when trying to.
public mainForm as form
and in your main form set mainForm=me
then you can access it from the second form....
you could also change the New constructor of your second form to accept a variable of type form, and pass the main form to the new constructor
im sure it's probably the wrong way of doing but i've declared each new form in the form that i'm calling it from.
though your last comment confused me though
"you could also change the New constructor of your second form to accept a variable of type form, and pass the main form to the new constructor"
sorry for waht i know is such a simple question. was mostly self taught at vb 6 and am now struggeling through my first .net project. but the help is much appreciated
sorry I'm reinstalling vs.net now so I cant write an example, sorry if I confused you:DQuote:
Originally posted by ronman1123
im sure it's probably the wrong way of doing but i've declared each new form in the form that i'm calling it from.
though your last comment confused me though
"you could also change the New constructor of your second form to accept a variable of type form, and pass the main form to the new constructor"
sorry for waht i know is such a simple question. was mostly self taught at vb 6 and am now struggeling through my first .net project. but the help is much appreciated
say this is your second form. if you open up the region where it says "Windows Form Designer generated code " you'll see the New constructor. You can change it to something like this:
VB Code:
' in the second form: Private callerForm as form #Region " Windows Form Designer generated code " Public Sub New(byval callerForm as form) me.callerForm = callerForm '..... End Sub .... ..... ...... #End Region private sub foo() ' you can access the other form like this callerForm.text = "boo" end sub
hope this explains it:D sorry I'm kinda bad in explaining something, hehe
edit: when you're creating a new form you have to pass the caller form to new(). IE, if your second form is called frmSecond and you are creating an instance of it, you should do something like this
VB Code:
dim frm as new frmSecond (me) ' pass "me" to the constructor frm.show()
okay i see what you were getting at
thanks much for the quick replies and the help