Click here to Skip to main content
15,921,793 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have form A with button A1 and form B with button B1.
when click on button A1, show dialog form B and when click on button B1, call event form_load of form A1.

please help me
thanks.
Posted

You can't directly raise the Load event from outside. This event is raised automatically when the form is shown (through Show or ShowDialog).

If you want to display a new form from a button handler, just instanciate that form and call its Show or ShowDialog method inside the button handler.

If you want to do something else, then please give more details.
 
Share this answer
 
v2
Comments
Espen Harlinn 18-Mar-11 5:49am    
Nice reply, my 5
You should study this link Opening form instances in C#

Best Regard,
Theingi Win
 
Share this answer
 
this[^] might help you.
 
Share this answer
 
Comments
ngthtra 18-Mar-11 4:36am    
I could not found any solution from your code. do you have idea?
thanks in advance
The thing is: Load event is not the "real" event in System.Windows.Forms, even thought technically it is the event. Maybe, the idea was to mimic Load event of System.Web.UI for very questionable "compatibility"? Who knows?
Anyway, what happens is this: when form is constructed and the event is fired (if its instance is not null), when InitializeComponent was already called.

For this reason, I never use this event, and do not advise to use it. In my opinion, it is done for marketing purpose, to strengthen the illusion of graphical programming. Instead, have some setup function which I directly call from the form constructor at the very end. I also use a separate file with the partial declaration.

That said, you cannot just fire this event for any reasonable purpose. The event is always fired in the class declaring the event; this is a very event-specific limitation (as opposed to other delegate instances). You can only create a Form instance and show the form and never need anything else related to form "Loading" (which, again is a "fake" notion).

Finally, making extra Form is a common design mistake. Just one Form, with, say tabbing interface is usually enough, but multiple forms are confusing the user. If your really need it, don't forget: make non-main forms owned by the main Form (see Form.OwnedForms) and set Form.ShowInTaskbar to false for non-main forms.

—SA
 
Share this answer
 

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