Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form.Load Event not triggerred

Status
Not open for further replies.

raghu75

Programmer
Nov 21, 2000
66
IN
Hi,
I have a form in a Dll. I have added that Dll Project to my application as a refernce.When I create an object of that form and call showdialog on that form the Form.Load event is not getting fired.Hence whatever code is there in that is not executing....ANy help ...in C#

Rgds
 
You will need to be more specific as I have had no trouble doing what you said. Perhaps how you are creating your form would help in solving your problem.

I started out with a c# windows application, added a c# class library to which I added a form. Added a button to the Windows Application form.

I used the following code to display the class library form from a button click event.

Code:
ClassLibrary1.Form1 window=new ClassLibrary1.Form1();
window.ShowDialog();
[\Code]

Within the Forms Load event I displayed a message box.

Everything worked fine form me. Keep in mind that the FormLoad event will occur only once when the form is initially displayed.
 
Hi,
I found that I am having two MS-Combobox on my form in the class library.They are of type AxMSForms.AxComboBox.
If I have this control on my form in the class library the showDialog is not invoking FormLoad event.

Pl. let me know how can i trigger FormLoad ...
 
The Load event is generated when you call showDialog.

I'm not familiar with these combo boxes - are they ActiveX controls or something?

From what you've said it appears that one of the comboboxes is consuming the load event before the parent can.

I don't know if this is possible with those controls, but If so, you may need some code associated with combobox to the event up to the parent by calling the appropriate method in the parent.

d-



Dean
---
 
I have seen this problem in VB.
There appears to be a bug in .NET where the load event is not fired when a form contains ActiveX controls and is displayed using the ShowDialog method.
My workround for this is to show the form and then hide it before the ShowDialog.
 
If there is indeed a bug, then GlynA has a good solution. It is possible that the show then hide operation will cause the form to flash on the screen, and that could be annoying. If that happens, then prior to showing the form for the first time you might try setting the Left or Top properties to a value that makes the form appear somewhere off the screen. But, don't forget to set the Left or Top property back to a more normal setting before you call ShowDialog().

Another solution might be to create a public method on the form that calls the Form1_Load() event method directly. Something like:

Code:
  public void FireForm_Load() {
    Form1_Load();
  }

Then, if you want to make sure that the load event only gets executed once for each time the form is instantiated, put some code like this inside the load event routine:


Code:
  if (!this.loadEventFired) {
    // event code goes here
    ..
    this.loadEventFired = true;
  }

and make sure you create a private boolean class variable called "loadEventFired".

So, when you call the ShowDialog() method, just add a call to FireForm_Load(), like this:

Code:
  ClassLibrary1.Form1 window=new ClassLibrary1.Form1();
  window.FireForm_Load();
  window.ShowDialog();

This solution would also prevent the Form1_Load() event code from being run more than once if the .Net bug was fixed in the future.
 
Raghu75 -

Another thing to check is your service pack level of your .NET framework. SP1 is available for framework v1.0, and of course, v1.1 of the framework was released the other week.

Chip H.
 
chiph -
Good point.

“I have always found that plans are useless, but planning is indispensable.” --Dwight Eisenhower
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top