1

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...

Rudy
  • 231
  • 1
  • 8
  • without seeing your code, it's going to be hard to make recommendations on how to improve your performance. – sous2817 Oct 31 '14 at 14:07
  • Some code would be smart to add here so someone can see and give you optimization ideas. – Wolf5 Oct 31 '14 at 14:08
  • Which UI framework are you using? WPF? Silverlight? Windows Runtime? WinForms? What does the problem code look like? Consider using a button rather than explicit click handling so you get keyboard handling automatically – Rob Caplan - MSFT Oct 31 '14 at 14:11

2 Answers2

1

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

Rudy
  • 231
  • 1
  • 8
  • 1
    I doubt one event would be slower than the other. The code is still queued to the UI thread as soon as it is fired. I believe the slowness you refer to is because the Clicked event will only fire after you have released the button, while MouseDown will fire immediately when you press the button. But the best way to learn is to often to fail first :) – Wolf5 Nov 03 '14 at 09:01
1

MouseDown helps, because you probably were getting double-clicks every second time instead of Click, when clicking fast. MouseDown is not affected by double clicking.

Arek
  • 1,276
  • 1
  • 10
  • 19