Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am having some troubles getting my mouse overs in the correct location when using scaletransform. I am using regions to check if the mouse is over a certain drawn image or text. It seems the way i have it now that the regions are scaling correctly, but they are to the left and right of where they should be at.

 

DesignWidth/Height is the width/height the screen/form is designed to be at, CurrentWidth/Height is the screen/forms current width/height

 

In Paint:

 

scaleX = CurrentWidth / DesignWidth

scaleY = CurrentHeight / DesignHeight

myGraphics.ScaleTransform(scaleX, scaleY)

 

Public Function HitTest(myObject as Object, x as point) as Boolean

Dim rect As New Rectangle(myObject.LocX * scaleX, myObject.LocY * scaleY, myObject.Width * scaleX, myObject.Height * scaleY)

If rect.Contains(x) Then return True

End Function

 

MouseMove calls HitTest()

 

I was reading about converting the Mouse Position to the Client Position, but only saw code for C, no VB code. I have tried compensating for the desktop location of the form, and that works until it is scaled to a different size, then the positioning is off again. Am I missing something that I should be compensating for?

 

Thanks,

 

liquid8

  • *Gurus*
Posted

You can get a Point structure of the mouse pointer's position relative to the upper-left corner of any control using this method:

 

myPoint = myControl.PointToClient(Cursor.Position)

 

That might help you get further, but you'll still have to adjust for your scaletransform I guess.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...