A
A
Alexey2016-08-06 10:22:41
C++ / C#
Alexey, 2016-08-06 10:22:41

How to implement double click (Double Click)?

I need a simple implementation of a double click in a unit in C#.
When you double click on an object, it rotates by a certain angle.
I can't come up with an algorithm... I searched on the Internet - I didn't find anything sensible. There was something on the forums, but they are in English ... and the code there was not clear to me.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Denis Gaydak, 2016-08-08
@Alexeee

simple implementation?) and click on objects.
then if you know how to code (judging by the description of the question, it’s unlikely) here’s a plan for you, so to speak
1) track the first click and start the timer
2) track the second click
3) check that the timer is not greater than the value (that double click is done quickly enough, then this parameter can be adjust for a pleasant experience)
4) check that the first and second clicks happened nearby (the coordinates are not far, some less than 1 percent of the screen space from each other)
if the timer is small and the clicks are nearby, it considers that there was a double click.
and there, at least by a beam, at least by the interface, the principle will remain the same.
and all this is not very difficult (but alas, write the code here for you from the phone) and it will be useful to do it yourself

G
GreatRash, 2016-08-06
@GreatRash

I searched on the Internet - I did not find anything sensible
I searched on the Internet - I did not find anything sensible

N
narntop, 2016-08-06
@narntop

Is this code understandable? Good example!)

UINT TimerId;
int clicks;

    VOID CALLBACK TimerProc(HWND hWnd, UINT nMsg, UINT nIDEvent, DWORD dwTime)
    {
        KillTimer(NULL, TimerId);
        if (clicks < 2 && !double_click){
            MessageBox(hWnd, L"Show Widget", L"Widget", MB_OK);
        }

        clicks = 0;
    }



  LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {

        int wmId, wmEvent;
        PAINTSTRUCT ps;
        HDC hdc;
        TCHAR szHello[MAX_LOADSTRING];
        LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
        UINT uID;
        UINT uMouseMsg;

        uID = (UINT)wParam;
        uMouseMsg = (UINT)lParam;

        if (uMouseMsg == WM_LBUTTONDBLCLK){
            double_click = true;
            MessageBox(hWnd, L"Double click", L"CAPT", MB_OK);
            return 0;
        }
        if (uMouseMsg == WM_LBUTTONDOWN){
            double_click = false;
            clicks++;

            //single click opens context menu
            if (clicks == 1){
                TimerId = SetTimer(NULL, 0, 500, &TimerProc);
            }
            return 0;
        }
    ,...
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question