Click here to Skip to main content
15,885,998 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am having problem with the Load event on a windows form that does not get fired when it is called from ShowDialog():
Form1 myForm = new Form1();
myForm.ShowDialog();

I had gone through the internet but have not find any solution yet. I have found this[^], but this is not my case since I do not use any ActiveX.
I have also tried to use Show() with no result.

Please help!

Thanks.
Posted
Updated 16-Aug-10 0:12am
v2
Comments
Nuri Ismail 16-Aug-10 6:14am    
Edited to enhance code formatting and to fix the problem with the provided link.

I'll bet it fires the first time you ShowDialog but not subsequent calls. I believe you need to call myForm.Dispose(); when done.
 
Share this answer
 
Comments
OriginalGriff 16-Aug-10 8:20am    
I don't think that is a good idea - once you have Disposed of an object, you aren't supposed to use it again! Better to kill the reference as well and use "new MyForm()" to construct a new instance.
It works fine for me - are you sure you have linked the event in?
If you are absolutely certain, and the method appears in the events list for your form, then do a clean rebuild, followed by a close and restart on VS.
 
Share this answer
 
Are you calling InitializeComponent() in all of your overloaded constructors?
 
Share this answer
 
Comments
Manfred Rudolf Bihy 30-Dec-10 18:56pm    
Or chain your constructor to one that does call InitializeComponent().
public FormWhatEver(...) : FormWhatEver( ... )
{
...
}
Chetan Ranpariya 31-Dec-10 2:34am    
Perfect answer.....
I've spent the last few hours struggling with the same thing. Never found anything online to help.

I think I've worked it out.

I was overloading the constructor of the form to allow me to set a property when creating the form. I think this stuffed it up.

When I just went back to the simple constructor, the load event started firing again.
 
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