00101010 10101010
00101010 10101010

Reputation: 313

WinForm Event-Handlers activating too slow

I'de like you to take a look at this code: I have a Button named Button1.

    private void button1_MouseHover(object sender, EventArgs e)
    {
        button1.BackColor = Color.Black;
    }

    private void button1_MouseLeave(object sender, EventArgs e)
    {
        button1.BackColor = Color.Blue;
    }

This code works but the problem is there is a very small delay. About 1/2 second delay on changing the colors. I've tried the same thing in WPF and there is absolutely no delay in that. Basically I want the Mouse event to fire as quickly as possible.

In what ways can i accomplish that task ? Thank you

Upvotes: 1

Views: 327

Answers (2)

Carsten
Carsten

Reputation: 11626

Calling button1.Invalidate(false) will result in redrawing the control within the next frame. Place this line right after your color-changing code and see if it works.

Upvotes: 0

Will A
Will A

Reputation: 25008

Try using the MouseEnter event rather than MouseHover - the latter is fired 'after a delay' because Windows can't tell that the mouse is hovering unless it has been stationary for a short while.

Upvotes: 5

Related Questions