Jump to content


Photo

Lab #2 Form Load Event Handler


  • Please log in to reply
2 replies to this topic

#1 SomeAverageName

SomeAverageName

    New Member

  • Members
  • Pip
  • 1 posts

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.

Edited by SomeAverageName, 01 July 2014 - 07:31 AM.


#2 darivuki

darivuki

    New Member

  • Members
  • Pip
  • 7 posts

Posted 01 July 2014 - 07:29 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();
        }


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.

Edited by darivuki, 01 July 2014 - 07:29 AM.


#3 AndrewStellman

AndrewStellman

    Andrew Stellman

  • O'Reilly Author
  • PipPipPipPipPipPipPipPipPipPipPip
  • 812 posts
  • 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

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 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users