6 Replies - 449 Views - Last Post: 29 November 2013 - 08:08 AM Rate Topic: -----

#1 Ryan5920  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 31
  • Joined: 17-October 13

MouseEnter and MouseLeave Events

Posted 28 November 2013 - 11:49 PM

I'm having a bit of trouble getting my MouseEnter and MouseLeave events to work. I have label3 set to false, and label3's visibility property should be getting changed by the MouseEnter and MouseLeave events of my MonthCalendar control.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GreenvilleAdvertisement
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            label2.Text = "Child, Teen, and Adult Competitions in:\n\nSinging\nDancing\nMusical Instrument\nOther";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            label2.Visible = true;
            monthCalendar1.Visible = false;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            label2.Visible = false;
            monthCalendar1.Visible = true;
        }

        private void monthCalendar1_MouseEnter(object sender, EventArgs e)
        {
            label3.Visible = true;

        }

        private void monthCalendar1_MouseLeave(object senver, EventArgs e)
        {
            label3.Visible = false;
        
        }
        private void label3_Click(object sender, EventArgs e)
        {
            label3.Visible = false;
            label3.Text = "Hello World!";
        }
    }
}



Is This A Good Question/Topic? 0
  • +

Replies To: MouseEnter and MouseLeave Events

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3552
  • View blog
  • Posts: 11,009
  • Joined: 05-May 12

Re: MouseEnter and MouseLeave Events

Posted 28 November 2013 - 11:58 PM

Remember that the calendar control in WinForms is a thin wrapper around the Windows common control calendar and so it may not have the full fidelity of the idealized WinForms control.

Have you tried other simple controls like a label or textbox control to see if you are getting the enter/leave events?

Anyway, I feel that you should abandon WinForms and use WPF instead. The controls implemented in WPF have more consistent behavior.
Was This Post Helpful? 0
  • +
  • -

#3 Ryan5920  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 31
  • Joined: 17-October 13

Re: MouseEnter and MouseLeave Events

Posted 29 November 2013 - 12:43 AM

The only reason I can't abandon this format is that is this is a homework assignment. I'm supposed to make label3 upon enter and leave to set to true and false. But I don't understand what I'm doing wrong.
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3552
  • View blog
  • Posts: 11,009
  • Joined: 05-May 12

Re: MouseEnter and MouseLeave Events

Posted 29 November 2013 - 12:50 AM

If you set breakpoints on line 33 and 39, are they even being called at least sometimes? If never, did you remember to hookup the events?
Was This Post Helpful? 0
  • +
  • -

#5 Ryan5920  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 31
  • Joined: 17-October 13

Re: MouseEnter and MouseLeave Events

Posted 29 November 2013 - 01:33 AM

I set the breakpoints you suggested and the functions are not being called. When my calendar shows up and put my mouse inside the calendar nothing happens at all.
Was This Post Helpful? 0
  • +
  • -

#6 Ryan5920  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 31
  • Joined: 17-October 13

Re: MouseEnter and MouseLeave Events

Posted 29 November 2013 - 01:44 AM

Ok when I tried hooking the events up it still didn't work. My newest attempt is here.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GreenvilleAdvertisement
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            label2.Text = "Child, Teen, and Adult Competitions in:\n\nSinging\nDancing\nMusical Instrument\nOther";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            label2.Visible = true;
            monthCalendar1.Visible = false;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            label2.Visible = false;
            monthCalendar1.Visible = true;
        }

        private void monthCalendar1_MouseEnter(object sender, EventArgs e)
        {
            label3.Visible = true;
            this.monthCalendar1.MouseEnter += new EventHandler(label3_Click);
            
        }

        private void monthCalendar1_MouseLeave(object senver, EventArgs e)
        {
            label3.Visible = false;
            this.monthCalendar1.MouseLeave += new EventHandler(label3_Click);
            
        }
        private void label3_Click(object sender, EventArgs e)
        {
            label3.Visible = false;
            label3.Text = "Hello World!";
        }
    }
}


Was This Post Helpful? 0
  • +
  • -

#7 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5481
  • View blog
  • Posts: 11,762
  • Joined: 02-June 10

Re: MouseEnter and MouseLeave Events

Posted 29 November 2013 - 08:08 AM

Lines 36 and 46 are a real problem. You are subscribing to those events EVERY TIME you mouse over. That means more and more and more subscriptions. They stack up.And they make no sense: On mouse enter you make another subscription to mouse enter?? WTF?

I get the distinct impression you aren't grasping how events, and subscribing to events works.

Check the C# tutorials: I created a tutorial just on mouse events. I'm doing this on my iPad or I would have a direct link to give you. You can also check my blog as there is an entry with a list of my tutorials.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1