scaletransform, regions, and mouseovers

liquid8

Active member
Joined
Jan 14, 2003
Messages
31
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
 
You can get a Point structure of the mouse pointers position relative to the upper-left corner of any control using this method:

Code:
myPoint = myControl.PointToClient(Cursor.Position)

That might help you get further, but youll still have to adjust for your scaletransform I guess.
 
Worked perfectly... thanks divil! :) I knew that function had to be in there somewhere..

liquid8
 
Back
Top