
Help altering main form from other forms
Here's a solutiuon don't know if it's a good way to code but it's simple as
it allows you access to the parent form directly in the child form (you can
select public procedures from the dropdown list as usual)
The instance of frmChild is created by form1 and passes a "Me" pointer to a
property in frmChild.
'In Main form:
'Form1: Add "button1" & label called "lblMessage"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim frmNew As New frmChild()
frmNew.ParentFrm(Me)
frmNew.Show()
End Sub
'Add a second form name it frmChild. Note Class level variable mfrmParent is
of type "Form1" not form, this ensures it exposes code added to parent
"Form1".
'Button1 is then used to send a message back to a label control "lblMessage"
on "Form1"
Dim mfrmParent As Form1
Property ParentFrm() As Form
Get
Return mfrmParent
End Get
Set(ByVal Value As Form)
mfrmParent = Value
End Set
End Property
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
mfrmParent.lblMessage.Text = "Child form was here!"
End Sub
Quote:
> Can someone help. Ill do a brief example of what i want to know.
> Suppose my main form is called frmMain, and another form is call frothier.
> Now in formalin I create a variable of type frmOther and call it x.
> Now I can alter any components of x using for instance x.Text = "New Text"
> All going fine,
> but now i want to click a button on x (frmOther) which will change a
> component on the main form frmMain.
> How do I do this?
> In other words i can change any form from frmMain but dont know how to
> detect and action on one of the other forms and alter a frmMain property.
> Hope this makes sense.
> In old VB each form could alter each other but vb.net is different.