Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi programmers,
 
I have two Windows forms: form1 and form2.
When closing form2, I want method form_load in form1 to start. How can I do this????
Posted 25-Jun-11 10:37am
Edited 25-Jun-11 16:53pm
v5
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

I think this is what you want:
 
in from1 write this:
 
public void Form1_Load(object sender, EventArgs e)
        {
            MessageBox.Show("hi");
        }
 
and in from2 write this:
 
private void Form2_FormClosed(object sender, FormClosedEventArgs e)
{
    Form1 frm = new Form1();
    frm.Form1_Load(sender,e);
 
}
 
hope it helps Smile | :)
  Permalink  
Comments
esmailian at 26-Jun-11 9:03am
   
Eroro:Form1_load(object,System.eventArgs) is Inaccessible due to its protection level
esmailian at 26-Jun-11 9:06am
   
Yes,it worked if public method in form1 THANKS friend
esmailian at 26-Jun-11 9:07am
   
I 5 good call
Uday P.Singh at 26-Jun-11 9:51am
   
thanks :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You can try this:
 
In the form_closed event of form2, write:
 
Form1 frm1 = new Form1(); 
frm1.ShowDialog(); 

Hope this helps. Smile | :)
  Permalink  
v3
Comments
esmailian at 26-Jun-11 2:18am
   
form1 always run.I need method loading restart
Uday P.Singh at 26-Jun-11 3:25am
   
see my new answer to get what you want.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

As the name suggests, this method is the handler of the "fictive" event Load. You should never call it directly!, it will mess-up things. Do you simply need to show another form? Instantiate form class and show instance? What you want to do makes no sense.
 
If you explain the purpose of it, you might get an advice on what to do.
 
—SA
  Permalink  
Comments
esmailian at 26-Jun-11 2:16am
   
I want when closed form2 submit my changes in form1 .
example : back color changes
SAKryukov at 29-Jun-11 5:23am
   
Sorry, first this is not the purpose. Why do you want it? Are you saying in form2 the user edits some changes, and they are updated in form1? As the user editing or when the form2 confirmed and closed? Is it modal or not? Why not having a master-detail controls on one form; with detail hidden when not used?
--SA
esmailian at 1-Jul-11 10:01am
   
Thank , my problem is solved.
SAKryukov at 3-Jul-11 1:54am
   
Well, will you accept this answer formally (green button)?
Thanks.
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

If you have form1 as your main entry point for the program (i.e. it's always open as long as your program is running), you won't want to reshow the form1 form.
 
In uday's example above, this assumes you want to create a new instance and how form1.
 
Instead, I'd recommend making a public method on form1 that form2 calls when form2's formClosing event is triggered.
 
Put what you want to run in the public method.
 
Does this "jive" with your thinking?
  Permalink  
v2
Comments
esmailian at 26-Jun-11 2:13am
   
No, I need change something in form1.loading form1 for submit my changes
jchoponis at 26-Jun-11 21:53pm
   
I see... I would still argue you could just expose a public property in form1 that would hold your result from form2. What exactly are you passing back to form1? Can you provide a snippet of your project so I can comment?

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

  Print Answers RSS
0 BillWoodruff 360
1 Mathew Soji 309
2 DamithSL 225
3 Afzaal Ahmad Zeeshan 202
4 Maciej Los 190
0 OriginalGriff 6,249
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 3,865


Advertise | Privacy | Mobile
Web02 | 2.8.1411019.1 | Last Updated 26 Jun 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100