Form references

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In VB6 I could pass a reference from another form or set a value of a control on a form from another form. I'm certain it can be done in VB.NET I just can't find a way to do it

In VB6 it would be something like

form1.label1.caption = strSomeValu

Or.....is there a new proper way to get a reference from another form? For instance how do we pass information from a Menu click on an MDIParent to an MDIChild

Thanks in advance

David
 
Where do you create the form you want to access? In VB.NET, the forms don't
"exist" in the namespace as instances - they are merely classes instantiated
at runtime. For example, my mainform has a variable called mysubform. At
some point in the program, I create the subform like this:

mysubform = new MySubFormClass (abc)

Now I can show the form:

mysubform.Show()

and of course, after executing "new", I now have an instance of the form I
can use:

mysubform.label1.caption = strSomeValue

If you want to access the main form, then store a reference to it in your
subform and pass in the mainform in the constructor.

David said:
In VB6 I could pass a reference from another form or set a value of a
control on a form from another form. I'm certain it can be done in VB.NET I
just can't find a way to do it.
In VB6 it would be something like.

form1.label1.caption = strSomeValue

Or.....is there a new proper way to get a reference from another form?
For instance how do we pass information from a Menu click on an MDIParent to
an MDIChild?
 
instance the second form just
below.
Inherits System.Windows.Forms.Form on Form1.
dim secform as new form2

just above end class make a property of secondform.

public Property firstname() as string
get
return textbox1.text 'dont forget return
end get
set(byval value as string) 'use word value
textbox1.text = value 'Or change value to
end set 'var of form2
end property

add more properties if desired.

to pass a string from form1 to form2 do this.

secform.firstname = "Bob"
Or
secform.firstname = textboxOnForm1.text

then show form secform.show
 
Back
Top