I'm working on a WordSearch puzzle program (also called WordFind) where you have to find certain words in a mass of letters. I'm using C# WinForms.
My problem is when I want to click and hold 1 letter(Label
), then drag over to other letters to change their ForeColor
. I've tried googling but to no avail.
Here is what I have:
foreach (Letter a in game.GetLetters())
{
this.Controls.Add(a);
a.MouseDown += (s, e2) =>
{
isDown = true;
a.ForeColor = Color.Yellow;
};
a.MouseUp += (s, e2) =>
{
isDown = false;
};
a.MouseHover += (s, e2) =>
{
if (isDown)
a.ForeColor = Color.Yellow;
};
}
However, the MouseHover event never fires unless the mouse is not being held down. Also no luck swapping MouseHover
with MouseEnter
. So, I kept the MouseDown
and MouseUp
events and tried using MouseHover within the form itself:
private void frmMain_MouseHover(object sender, MouseEventArgs e)
{
if (isDown)
{
foreach (Letter l in game.GetLetters())
if (l.ClientRectangle.Contains(l.PointToClient(Control.MousePosition)))
l.ForeColor = Color.Purple;
}
}
This event does not fire either and I'm at a loss as to why it's not firing and what some alternative solutions are. Any advice is appreciated.