O'Reilly Forums: Lab #2 Form Load Event Handler - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Lab #2 Form Load Event Handler Load event handler not running

#1 User is offline   SomeAverageName 

  • New Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 01-July 14

Posted 01 July 2014 - 07:11 AM

I've written up the start of the form for this lab as it says in the book (2nd edition), but Form1_Load doesn't seem to run at all. I don't understand what the reason for this is. I've checked a couple other people's examples with pretty much identical code here where their Form1_Load does run when the program starts. Any help?

public partial class Form1 : Form
    {
        private Game game;
        private Random random = new Random();

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            game = new Game(new Rectangle(78, 57, 420, 155));
            game.NewLevel(random);
            UpdateCharacters();
        }


Edit: Nevermind, I found that you need to add Form1_Load to the Load section under the forms Events in the properties window.

This post has been edited by SomeAverageName: 01 July 2014 - 07:31 AM

0

#2 User is offline   darivuki 

  • New Member
  • Pip
  • Group: Members
  • Posts: 7
  • Joined: 18-March 14

Posted 01 July 2014 - 07:29 AM

View PostSomeAverageName, on 01 July 2014 - 07:11 AM, said:

I've written up the start of the form for this lab as it says in the book (2nd edition), but Form1_Load doesn't seem to run at all. I don't understand what the reason for this is. I've checked a couple other people's examples with pretty much identical code here where their Form1_Load does run when the program starts. Any help?

public partial class Form1 : Form
    {
        private Game game;
        private Random random = new Random();

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            game = new Game(new Rectangle(78, 57, 420, 155));
            game.NewLevel(random);
            UpdateCharacters();
        }



Where do you call Form1_Load? And why don't you do this after the InitializeComponent() method?
Try to add the three lines from Form1_Load under the InitializeComponent() method and see what happens.

This post has been edited by darivuki: 01 July 2014 - 07:29 AM

0

#3 User is offline   AndrewStellman 

  • Andrew Stellman
  • PipPipPipPipPipPipPipPipPipPipPip
  • Group: O'Reilly Author
  • Posts: 749
  • Joined: 08-October 08
  • Gender:Male
  • Location:Brooklyn, NY
  • Interests:Author of: "Head First C#", "Beautiful Teams", "Head First PMP", "Applied Software Project Management"

Posted 01 July 2014 - 04:45 PM

Quote

Edit: Nevermind, I found that you need to add Form1_Load to the Load section under the forms Events in the properties window.


Exactly!! :) You set it just like you set the form's TextChanged event handler back on page 223 in chapter 6, using the lightning bolt button.
Andrew Stellman
Author, Head First C#
Building Better Software -- http://www.stellman-greene.com
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users