A form within a form in 2005

R

Ryan

I have three forms in my application; frmMain being the main form:
frmMain containing two button; btnDisplayForm1 and btnDisplayForm2
FormA containing a button btnProcessRequestA
FormB containing a button btnProcessRequestB

frmMian is displayed and the FormB is displayed inside frmMain using
SetParent; I click on btnDisplayForm1 which fires up the following code:
FormA frm = new FormA ();
Button btn = frm.btnProcessRequestA;
this.InvokeOnClick(btn, EventArgs.Empty);

When btnProcessRequestA is fired up on FormA; it displays FormB.

How do I display FormB inside frmMian?
 
R

Ryan

I have tried the following code but got the error: {"Unable to find an entry
point named 'SetParent' in DLL 'gdi32.dll'.":""}

FormB formB = new FormB();
frmMain fMain = new frmMain
SetParent(formB.Handle, fMain.Handle);
formB.Show();
 
I

Ignacio Machin ( .NET/ C# MVP )

I have three forms in my application; frmMain being the main form:
frmMain containing two button; btnDisplayForm1 and btnDisplayForm2
FormA containing a button btnProcessRequestA
FormB containing a button btnProcessRequestB

frmMian is displayed and the FormB is displayed inside frmMain using
SetParent; I click on btnDisplayForm1 which fires up the following code:
FormA frm = new FormA ();
Button btn = frm.btnProcessRequestA;
this.InvokeOnClick(btn, EventArgs.Empty);

When btnProcessRequestA is fired up on FormA; it displays FormB.

How do I display FormB inside frmMian?

why you do that?
why not use a Panel instead of a form?
 
R

Ryan

Ignacio,
If I go with your suggestion and use a panel to display FormA and FormB; how
do I pass values between these two forms?

If I use the code:
FormA frm = new FormA();
Button btn = frm.button1;
this.InvokeOnClick(btn, EventArgs.Empty);

the button click event is invoked but the form is displayed outside the
panel and the values aren't passed to FormB. The code for the FormB is:
Form3 frm = new Form3();
frm._textBox1 = _textBox1;
frm.Show();

I need to toggle between two forms and pass value between them.

Thanks
 
I

Ignacio Machin ( .NET/ C# MVP )

Ignacio,
If I go with your suggestion and use a panel to display FormA and FormB; how
do I pass values between these two forms?  

See it like this, instead of using form use a control , so you have
two controls ControlA & ControlB hosted in the same form. how do you
pass values between then depends if either ControlA or ControlB knows
about the other.
In a templated solution you will have methods in the container
(Form1) that detect thte changes in ControlA and then call the method
in ControlB

hope that it's clear for you. if not post back
 
R

Ryan

Could you please privde a sample code???

Ignacio Machin ( .NET/ C# MVP ) said:
See it like this, instead of using form use a control , so you have
two controls ControlA & ControlB hosted in the same form. how do you
pass values between then depends if either ControlA or ControlB knows
about the other.
In a templated solution you will have methods in the container
(Form1) that detect thte changes in ControlA and then call the method
in ControlB

hope that it's clear for you. if not post back
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top