Cursor.Clip code no longer works: Upgraded VB .net 2008 framwork 2.0 to 2010 framework 3.5

My program worked fine in 2008 with 2.0 framework.

I updated it to 2010 and framework 3.5

Now this code does not work anymore.  It does not confine the cursor like it did before.

What it is supposed to do is confine the mouse movement to the PictureMap.  But now it lets the mouse work everywhere..  

Is there a new way to code this for 2010 3.5 framework?
TreasureBox = New Rectangle(R.Next(5, PictureMap.Width - 5), R.Next(5, PictureMap.Height - 5), 1, 1)
        TreasureBox.Inflate(6, 6)


        Dim rc As Rectangle = Panel1.RectangleToScreen(PictureMap.Bounds)
        Cursor.Position = New Point(rc.Location.X + rc.Width / 2, rc.Location.Y + rc.Height / 2)

        Cursor.Clip = rc

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonMiddle School Assistant TeacherCommented:
I can't see anything wrong, assuming PictureMap is actually contained by Panel1.  The code works for me in a simple test.

When does this code get run?
hagoogAuthor Commented:
on a button click.

It is on panel1.
Very strange because it worked before fine and only stopped after I upgraded to program to 2010 and changed framework to 3.5

before it was 2008 and 2.0
Mike TomlinsonMiddle School Assistant TeacherCommented:
Perhaps something is wrong with just that upgraded project.   Try out a simple test in a NEW project and see if the problem still persists...
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

hagoogAuthor Commented:
It seems like I can not make it move the mouse pointer..

It seems like the problem I have is that this code does not relocate the mouse pointer..

    Dim rc As Rectangle = Panel1.RectangleToScreen(MapPic.Bounds)
        Cursor.Position = New Point(rc.Location.X + rc.Width / 2, rc.Location.Y + rc.Height / 2)

even this line does not relocate the mouse pointer
        Cursor.Position = New System.Drawing.Point(10, 10)
hagoogAuthor Commented:
I created a new project and just added a button and put this in  the click event

Cursor.Position = New System.Drawing.Point(10, 10)

pointer did not relocate!
hagoogAuthor Commented:
created new project only this code..

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim rc As Rectangle = RectangleToScreen(MyMap.Bounds)
        Cursor.Position = New Point(rc.Location.X + rc.Width / 2, rc.Location.Y + rc.Height / 2)
        Cursor.Clip = rc

    End Sub
End Class

But it does not relocate the pointer.

It is seeming to lock the app  - like modal.. only control alt delete and killing the instance allows me to return to the DEV env or desktop,,  but mouse can move anywhere on screen..
Mike TomlinsonMiddle School Assistant TeacherCommented:
That code works for me.  =\

The cursor jumps and is bound to MyMap. something else is wrong with either your DEV environment or your computer itself.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.