Form Load Event never fired
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 27

Thread: Form Load Event never fired

  1. #1
    Join Date
    Jul 2009
    Posts
    12

    Thumbs down 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

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,384

    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.

  3. #3
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,990

    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()
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  4. #4
    Join Date
    Jul 2009
    Posts
    12

    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

  5. #5
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    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
    win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming

    remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation

    private lessons are not an option so please don't ask for help in private, I won't replay

    if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know

  6. #6
    Join Date
    Jul 2009
    Posts
    12

    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

  7. #7
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,384

    Re: Form Load Event never fired

    It is a bug (but not in Microsoft's code).

    Post the form code including the autogenerated code.

  8. #8
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,990

    Re: Form Load Event never fired

    Try it with a new form. If it works, copy the controls and test it.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  9. #9
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    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.

  10. #10
    Join Date
    Jul 2009
    Posts
    12

    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...");
    
            }
    
        }
    }
    Last edited by Shuja Ali; July 5th, 2009 at 06:03 AM. Reason: Added code tags

  11. #11
    Join Date
    Jul 2009
    Posts
    12

    Re: Form Load Event never fired

    And since the autogenerated code is too long, I've attached it.

    Thanks,
    Jerad
    Attached Files Attached Files

  12. #12
    Join Date
    Jun 2008
    Posts
    2,477

    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.

  13. #13
    Join Date
    Mar 2004
    Location
    3311'18.10"N 9645'20.28"W
    Posts
    1,808

    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");
        }
    }

  14. #14
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Form Load Event never fired

    While I would agree with MadHatter, it should still work.

  15. #15
    Join Date
    Jul 2009
    Posts
    12

    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

Page 1 of 2 12 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center