Quantcast
Viewing all articles
Browse latest Browse all 12583

bug? MouseLeave + ShowInTaskbar (false)

Hey there, I think I have come across a bug, or at least an odd behavior.  Can anybody explain this?  Any ideas of a workaround?

If a control is being hovered (MouseEnter has fired) when form is minimized, then the MouseLeave will not fire if ShowInTaskbar is set to false.

The following simple form demonstrates the problem.  On MouseEnter, the button background is set to purple.  In MouseLeave, the button background is cleared.  In button Click, the form is Minimized.  When the form is restored, the button background will be normal (ie MouseLeave has fired) if the formwas shown in the taskbar.  If it is not in the taskbar, then the button will still be purple, becuase MouseLeave never fired.  Here is the code:

using System;
using System.Drawing;
using System.Windows.Forms;

namespace Test
{
    class TestForm : Form
    {
        private Button button = new Button();
        private CheckBox checkbox = new CheckBox();
        
        public TestForm()
        {
            button.Location = new Point(25, 25);
            button.Size = new Size(150, 25);
            button.MouseEnter += new EventHandler(button_MouseEnter);
            button.MouseLeave += new EventHandler(button_MouseLeave);
            button.Click += new EventHandler(button_Click);
            checkbox.Location = new Point(25, 75);
            checkbox.Size = button.Size;
            checkbox.Text = "Show in Taskbar?";
            ClientSize = new System.Drawing.Size(200, 150);
            Controls.Add(button);
            Controls.Add(checkbox);
        }

        void button_Click(object sender, EventArgs e)
        {
            // order of the next two statements does not matter
            ShowInTaskbar = checkbox.Checked;              
            WindowState = FormWindowState.Minimized;
        }

        void button_MouseLeave(object sender, EventArgs e)
        {
            // this event will not fire if form is minimized while ShowInTaskbar is false
            button.BackColor = Color.Empty;
        }

        void button_MouseEnter(object sender, EventArgs e)
        {
            button.BackColor = Color.Purple;
        }
    }
}

Any ideas?

Thanks,
Ryan


Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>