-
Form Load Event never fired
I'm very new to C# and Visual Studio but I'm finding my way around a bit.
I'm completely stumped on this issue. I don't know what I have done to cause my form to do this... I have several forms which all work correctly except this one (and it worked right at one point...).
To make a long story short, the Form_Load event is never actually touched when my form is loaded.... To verify this, I added MessageBox.Show("Test"); inside of it and the form actually loads but any code in the _Load event isn't ran...
I know it sounds strange and I'm hoping it's just something like a simple and stupid thing that I have done...
Thank you,
Jerad
-
Re: Form Load Event never fired
Open the form in the Visual Studio form editor.
Open the properties window (right click on the form and choose 'properties').
Click on the lightning bolt in the properties window. This displays the events viewer.
Find the OnLoad event and make sure it's still attached to your on load handler.
-
Re: Form Load Event never fired
A form only loads ONCE, unless you UNLOAD it. If you call it again, it is already in memory. Use .Invalidate when the form starts. In VB6, it was Form_Activate()
-
Re: Form Load Event never fired
Arjay, thanks for the response. I'm not sure if I'm dense or what but I do not see an "OnLoad" event. I'm using Visual Studio 2005 if that matters. When I open the form and go to it's properties, I see the Load event which when I double click it, it takes me to the code where my messagebox is located...
Your quote "Find the OnLoad event and make sure it's still attached to your on load handler. " is interesting as that sounds like it but not sure how to find it..
Also, another note... I have another form that has Load events and I created a breakpoint right at the load event. When I debug and open the form, it stops in Visual Studio and lets me step through the Load event. If I do this to the form that isn't working, visual studio never hits the breakpoint.... It's so weird and I'm not sure what's going on.
Thanks,
Jerad
-
Re: Form Load Event never fired
because it's called Load event
http://msdn.microsoft.com/en-us/libr...form.load.aspx
and how to do it
http://msdn.microsoft.com/en-us/libr...20(VS.71).aspx
form's load event handler funciton is not attached to the Load event I guess
-
Re: Form Load Event never fired
I know it's strange but the load event is attached... I'm beginning to think this is a bug. In the form's properties I've chosen the Load event and gave it a name, double clicked it and wrote the code in the event.
I really think this is a bug now...
Thanks,
Jerad
-
Re: Form Load Event never fired
It is a bug (but not in Microsoft's code).
Post the form code including the autogenerated code.
-
Re: Form Load Event never fired
Try it with a new form. If it works, copy the controls and test it.
-
Re: Form Load Event never fired
If you are worried about the code of your application, you can attach just that form to your reply and someone here may take a look at it. I suppose it has got something to do with the recent changes that you might have made to the form or maybe by mistake you removed or added a piece of code.
-
Re: Form Load Event never fired
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace thePolicyHunters
{
public partial class LifeInsurance : Form
{
public LifeInsurance(string lRecordKey)
{
InitializeComponent();
tmp.Text = lRecordKey.ToString();
}
private void commissionPendingLabel_Click(object sender, EventArgs e)
{
}
private void commissionPendingTextBox_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
}
private void groupBox1_Enter(object sender, EventArgs e)
{
}
private void fillByToolStripButton_Click(object sender, EventArgs e)
{
}
private void filterLifeToolStripButton_Click(object sender, EventArgs e)
{
}
private void insuranceCommentsDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void insuranceCommentsDataGridView_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)
{
e.Row.Cells["RecordKey"].Value = recIDTextBox.Text;
e.Row.Cells["CommentType"].Value = "Life";
}
private void LifeInsurance_Load(object sender, EventArgs e)
{
MessageBox.Show("Loading...");
}
}
}
-
1 Attachment(s)
Re: Form Load Event never fired
And since the autogenerated code is too long, I've attached it.
Thanks,
Jerad
-
Re: Form Load Event never fired
Everything looks fine in the sample code you provided, and there is definitely not a bug in the Load event, so can you post your entire project please? Something else is going on.
-
Re: Form Load Event never fired
#1 rule:
- Do not attach to your own events. Override the method that fires the event (In this case it's the onload method):
Code:
public class Form1 : Form {
protected override OnLoad(EventArgs e) {
base.OnLoad(e);
MessageBox.Show("I always get called");
}
}
-
Re: Form Load Event never fired
While I would agree with MadHatter, it should still work.
-
Re: Form Load Event never fired
MadHatter, I usually do not and I understand.
BigEd, I would love to post the entire project which I can, except most of the stuff requires the SQL database that I have on my machine. If I upload the project, will you be able to use it even though you won't have the database?
Also, on another note. I TRUELY appreciate your guy's help. This is awesome that you would take time out of your day to help others out. THANK YOU!!!
Thanks,
Jerad
-
Re: Form Load Event never fired
We can isolate out the DB stuff.
-
Re: Form Load Event never fired
You're amazing.
Thanks again. Also, please excuse the probably dirty code. I'm just starting this so I'm sure there are plenty of things I'm doing wrong...
I'm a BizTalk developer... :)
Thanks,
Jerad
P.S- Actually I can't seem to upload it. My project is 1 MB zipped and the max I can post is 500kb... Can I e-mail it to you??
-
Re: Form Load Event never fired
You can upload to a place like megaupload for free and then just provide the link.
-
Re: Form Load Event never fired
Alright, awesome.
Here's the link.
http://www.megaupload.com/?d=WWUUKZW0
Thanks,
Jerad
-
Re: Form Load Event never fired
I looked at your project and noticed that the only creation of the "Clients" class has been commented out. This is the only class that creates a "LifeInsurance" instance, so I just added a button to the startup form ("Switchboard") which creates a LifeInsurance form. The load event fired as expected and he "Loading..." messagebox appeared, so I am not sure what your problem really is.
http://i227.photobucket.com/albums/d.../delete-86.jpg
-
Re: Form Load Event never fired
Alrighty, so what you're saying is you didn't see anything wrong?
That's strange. So what I just did (since it worked on yours...) is I opened the Switchboard form. Then added a button and on the button I added:
LifeInsurance LI = new LifeInsurance("RecordKey");
LI.Show();
When I ran this and clicked the button, the LifeInsurance form was instantiated but the "Loading..." message box never appeared. Can you send me back what you changed and let me see if it works on my machine. If yours doesn't (and you know it works on yours..) then could it be specific to my computer settings or something? I know that sounds crazy..
Thanks,
Jerad
-
Re: Form Load Event never fired
Code:
public partial class Switchboard : Form
{
public Switchboard()
{
InitializeComponent();
button1.Click += button1_Click;
}
private void button1_Click(object sender, EventArgs e)
{
LifeInsurance frm = new LifeInsurance( "foo" );
frm.Show( );
}
}
-
Re: Form Load Event never fired
Yep, I do that exact same thing and it's never fired..
Is this a lost cause?
Thanks,
Jerad
-
Re: Form Load Event never fired
I just tried this by adding a temporary button to the SwitchBoard form as BigEd did and got a binding error with "RatingClassandQuote". This caused the LifeInsurance form not to appear. I commented out this binding in the LifeInsurance.Designer.cs file and the event fired and form appeared.
Quote:
Originally Posted by
JMSWebDesign
Is this a lost cause?
Are you doing this by adding a temporary button on the SwitchBoard form?
-
Re: Form Load Event never fired
on my machine the Load event also fires
-
Re: Form Load Event never fired
Quote:
Originally Posted by
JMSWebDesign
P.S- Actually I can't seem to upload it. My project is 1 MB zipped and the max I can post is 500kb... Can I e-mail it to you??
Usually you delete the \bin and \obj folders before zipping. You'll need to move the StaffDotNet.xxx.dll binary into the project folder. This will get the zipped file down to about 250K. In general, you'll want to remove these folders before zipping the project.
-
Re: Form Load Event never fired
Thanks guys for all of your help. I think I will start the form from scratch and test along the way. I created a blank form and put the load event on it. When ran, the load event was fired. So then I took my old form and copied all of the controls and pasted them on to the newly created form (that worked). Once I pasted the controls on the new form and ran it, the load event was not fired........
I'm going to use Snag-It later on tonight and post a link to the video of what I am doing. I swear, to me this looks like some strange anomaly....
Thanks,
Jerad