dev520
dev520

Reputation: 179

MouseEventArgs Location wrong when use sizemode fit

I have a rectangle, when I click on this, this will display to another view

I'm using Rectangle.Contains(e.Location) (e is MouseEventArgs) This is ok when SizeMode is normal: https://i.sstatic.net/ydQCn.png

But when I set the display SizeMode to fit, the Rectangle has to go to another location, but I must click on old location same as SizeMode normal https://i.sstatic.net/PUPsC.png

I think I need scale rectangle when go to fit mode, but I don't know the ratio. Please help me

Upvotes: 2

Views: 128

Answers (2)

Frenchy
Frenchy

Reputation: 17027

To calulate the ratio of rectangle, you could calculate ratio = Width / Height

So width and height are always linked by this formula, if you want to keep the same ratio

if you know the new width, new height = new width / ratio

or

if you know the new height, new width = ratio * new height

Upvotes: 0

x5657
x5657

Reputation: 1202

You might need to map the screen co-ordinates to control co-ordinates. Take a look at the helper PointToClient.

Upvotes: 1

Related Questions