tags:

views:

86

answers:

1

I am implementing shape resizing using corner handles. In some cases, certain moves with the mouse holding the handle are not legit, e.g. if it will in effect extend it beyond the control boundary. So what I would like to do in this case is "cancel" the mouse move in flight programmatically, so that the mouse would just stay within the bounds of the stationary handle rectangle. How do I do this?

+1  A: 

try using ClipCursor api function (http://msdn.microsoft.com/en-us/library/ms648383%28VS.85%29.aspx)

Below is an example:

[DllImport("user32.dll")]
static extern bool ClipCursor(ref RECT lpRect);

public struct RECT
{
    public int Left;
    public int Top;
    public int Right;
    public int Bottom;

    public RECT(int left, int top, int right, int bottom)
    {
        Left = left;
        Top = top;
        Right = right;
        Bottom = bottom;
    }
}

private void button7_Click(object sender, EventArgs e)
{
    RECT rect = new RECT(Left, Top, Width, Bottom);
    ClipCursor(ref rect);
}

regards

serge_gubenko