Hey everyone,

I want to restrict cursor movement outside of a picture box when the user clicks a button. Here's what my code looks like so far:

private void btnX_Click(object sender, EventArgs e)
        {
            if (remote == false)
            {
                remote = true;
                Cursor.Position = pctRemote.PointToScreen(gridCenter);  //centers the cursor on the grid
            }
            else
            {
                remote = false;
                Cursor = Cursors.Default;
            }
            
        }

PictureBox = pctRemote

I've tried a lot of cursor.clip functions but I can't seem to get it working.

What was wrong with all the info in your "mousemove" thread? that had the answers to this? Which isnt included at all in your above code

I wanted to start a new thread that was focused on this topic.

Cursor.Capture doesn't exist (according to VS2008)

Also, it kept clipping to the wrong portion of the screen. Couldn't figure out how to move the clipped portion to be in the same position as the picture box.

Then you have semi working code to post, and a more precise problem than getting people who may not have read your other thread to do all the work again for you.

If its in the wrong position most likely its because you didnt allow for the fact that the top of the thing you're restricting it a) can move, b) the clip is on the scren not on the form... so.. you need to know where it all is in relation to the screen

thanks I'll test that out and post the code if I have problems

Ok I've got a lot working!!

Here's the code:

private void btnX_Click(object sender, EventArgs e)
        {
            if (remote == false)
            {
                remote = true;
                Cursor.Position = pctRemote.PointToScreen(gridCenter);  //centers the cursor on the grid
                Cursor.Clip = pctRemote.RectangleToScreen(pctRemote.ClientRectangle); //confines mouse to grid perimater
            }
            else
            {
                remote = false;
                Cursor = Cursors.Default;
                /*  NEED HELP HERE   */
            }
            
        }

Now I need help switching the Cursor.Clip off. How can I do that?

Thanks!

Simplest way would be to remember the previous setting before you set your own, and restore it.

Hm, how can I see what it was? Sorry if that's a dumb question

Check what the helpfile says about the routine :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.