Click here to Skip to main content
15,896,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I created three forms and in each form there is a button. I managed to open the second form using MDI by putting this code:
C#
Form2 Utilisateur = new Form2();
                Utilisateur.MdiParent =this;
                Utilisateur.Show();

But now I need to open the third form being on the second form using MDI, how could I do it ?
Thank you.

What I have tried:

I did the first step. On clicking on the button of the first form it opens the second form but now I want to open the third form b clicking on the button of the second form.
Posted
Updated 4-Jul-16 5:19am

1 solution

The best way is not to.
Instead, create an event in your Form2, which its parent handles.
Your button raises the event, the parent handles it and creates the new instance in teh same way it created Form2.
This should help: Transferring information between two forms, Part 2: Child to Parent[^]
 
Share this answer
 
Comments
TatsuSheva 4-Jul-16 11:35am    
There is no another method ?
OriginalGriff 4-Jul-16 11:42am    
None that make sense within the OOPs environment - it's all about separation of concerns.
It's really not difficult - creating an event is only a few lines of code, and signaling it is only one line! And the link includes the code to do all of that.
TatsuSheva 4-Jul-16 11:48am    
In your case, it was a transfer of data but mine it is to open a form with the MDI method, do you think it will work ?
OriginalGriff 4-Jul-16 12:04pm    
Of course it will!
In your case the information you are transferring is "the user asked for Form3", which just needs the event - you don't need a property in this case.

Think about it: it's the same as a TextBox signaling the TextChanged event - it doesn't care what your form does with that, it just indicates it happened.
TatsuSheva 4-Jul-16 12:14pm    
Okay, I will try my best.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900