Click here to Skip to main content
13,089,818 members (48,028 online)
Rate this:
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 9:37am
Updated 25-Jun-11 15:53pm
Rate this: bad
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)

and in from2 write this:

private void Form2_FormClosed(object sender, FormClosedEventArgs e)
    Form1 frm = new Form1();

hope it helps :)
esmailian 26-Jun-11 9:03am
Eroro:Form1_load(object,System.eventArgs) is Inaccessible due to its protection level
esmailian 26-Jun-11 9:06am
Yes,it worked if public method in form1 THANKS friend
esmailian 26-Jun-11 9:07am
I 5 good call
Uday P.Singh 26-Jun-11 9:51am
thanks :)
Rate this: bad
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(); 

Hope this helps. :)
esmailian 26-Jun-11 2:18am
form1 always run.I need method loading restart
Uday P.Singh 26-Jun-11 3:25am
see my new answer to get what you want.
Rate this: bad
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.

esmailian 26-Jun-11 2:16am
I want when closed form2 submit my changes in form1 .
example : back color changes
SAKryukov 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?
esmailian 1-Jul-11 10:01am
Thank , my problem is solved.
SAKryukov 3-Jul-11 1:54am
Well, will you accept this answer formally (green button)?
Rate this: bad
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?
esmailian 26-Jun-11 2:13am
No, I need change something in form1.loading form1 for submit my changes
jchoponis 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
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170813.1 | Last Updated 26 Jun 2011
Copyright © CodeProject, 1999-2017
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