event handler to detect mouse drag on picture box(winforms,c#)

.net, c#, event-handling, winforms

Solution

Handle `MouseDown` and set a boolean variable to true. Handle `MouseMove` and, if the variable is set to true and the mouse's movement is above your desired treshold, operate. Handle `MouseUp` and set that variable to false.

Example:

bool _mousePressed;
private void OnMouseDown(object sender, MouseEventArgs e)
{
    _mousePressed = true;
}

private void OnMouseMove(object sender, MouseEventArgs e)
{
    if (_mousePressed)
    {
        //Operate
    }
}

private void OnMouseUp(object sender, MouseEventArgs e)
{
    _mousePressed = false;
}

Problem

I am making simple paint application in which a line would be drawn whenever someone holds down the mouse button and drags(exactly like in windows paint). However i am having a hard time finding the suitable event handler for this. MouseDown is simply not working and MouseClick is only jotting down dots whenever i press a mouse down. Need help in this matter. Thanks.

Original source