Help altering main form from other forms 
Author Message
 Help altering main form from other forms

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.



Thu, 25 Nov 2004 03:27:05 GMT  
 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.



Fri, 26 Nov 2004 13:31:00 GMT  
 Help altering main form from other forms
Thanks for that, Ill use that code. Its just seems like there should be
another way.



Quote:
> 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



> > 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.



Sun, 28 Nov 2004 04:23:18 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. changing stuff in your main form from another form

2. Unhandled exception in system.windows.forms.dll (in my main form) - argh

3. how to change properties of the main form from a another form

4. maximize child form display multiple tool box controls on main form

5. create main form and Sub Form

6. Forms on top of Main Form

7. VB3: modal form gets hidden by main MDI form in Win98

8. How to auto size the main form/ MDI form

9. adding controls from other forms to main form

10. create Main Form Sub form in VB6

11. How to switch Main form to other form?

12. Problem showing a Splash Form and then a Main Form (The Main form does not get control.)

 

 
Powered by phpBB® Forum Software