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