Search code examples
c#performanceeventspanelbackcolor

c# backcolor of panel changing is slow (that or the event is slow)


I am making a variant on the game mastermind in VS2013 in c#. The problem I have is that I made 4 small panels that people can click on to set their code. When they click on the panel, an event is launched which changes the background color of the panel. My problem is if I click the panels, the color change is too slow. This is mostly noticeable when you try to scroll through the colors quickly. It'll take a good half second before switching to the next one after just switching. I have tried commenting every bit of code I do on the event out except for the color change but it doesn't help So I don't believe it's that the code takes too long to run. Anybody have experience with this?

EDIT: Using the standard Forms that are in Visual Studio 2013 here's the code some of you asked for... it's not much though

    private void InputCode1Clicked(object sender, EventArgs e)
    {
        code1++;
        if (code1 > 5)
        {
            code1 = 0;
        }
        this._input1.BackColor = ENUMS.GetColor((ENUMS.color)code1);
        _controller.InputCodeClicked(sender, e, 1);
    }

keep in mind, even like this:

    private void InputCode1Clicked(object sender, EventArgs e)
    {
        this._input1.BackColor = ENUMS.GetColor((ENUMS.color)code1);
    }

it still runs slow...


Solution

  • FIXED IT! Using a mouseDown event instead of a mouseclicked/clicked event solved my problem...