Hi all,

I'm following this tutorial and I'm encountering strange behaviour with the program.

My finishLabel ought to be calling finishLabel_MouseEnter() when the mouse hovers over it, but it's calling wall_MouseEnter() instead - the location of the mouse resets and the congratulations box doesn't show up. In the properties/events box for the label, finishLabel_MouseEvent is selected. In Form1.Designer.cs,

`// `
`// finishLabel`
`// `
`this.finishLabel.AutoSize = true;`
`this.finishLabel.Location = new System.Drawing.Point(467, 430);`
`this.finishLabel.Name = "finishLabel";`
`this.finishLabel.Size = new System.Drawing.Size(34, 13);`
`this.finishLabel.TabIndex = 15;`
`this.finishLabel.Text = "Finish";`
`this.finishLabel.MouseEnter += new System.EventHandler(this.finishLabel_MouseEnter);`

describes my finishLabel, and there are no other 'this.finishLabel.MouseEnter' lines.
In Form1.cs,

`private void finishLabel_MouseEnter(object sender, EventArgs e)`
`    {`
`        // Show a congratulatory MessageBox, then close the form.`
`        MessageBox.Show("Congratulations!");`
`        Close();`
`    }`

describes how the method should be working.

I tried changing the event box selection back and forth between the two available events, and restarting the IDE (Visual Studio 2012 Express for Desktop) in case it was an error there, but regardless of how I run the program the finishLabel behaves incorrectly.

Any ideas on what the problem might be?
Thanks in advance,

3 Years
Discussion Span
Last Post by DevonParsons

I just tried the tutorials code and it works exactly as advertised. Not sure where your problem could be. Try deleting the finishLabel, and adding a new one, then set the MouseEnter handler again and see what happens.


Solved. The problem had to do with the fact that the panel that contained the maze elements also had a MouseEnter and MouseLeave event that called wall_MouseEnter - so the user couldn't just take the mouse outside the game to cheat. After removing those two event handlers from Form1.Designer.cs, finishLabel behaved properly. To deal with the 'cheating' problem, simply wrap the maze in walls - not that it's hard to cheat in a program this simple anyways.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.