Size from two Point variables

  • Thread starter Thread starter Dan Reber
  • Start date Start date
D

Dan Reber

I have to Point variables that are being set on MouseDown and MouseUp
events --

mousedownPoint = new Point(e.X, e.Y);
mouseupPoint = new Point(e.X, e.Y);

Is there a way that I can take those two points and get a Height and Width
value from it to use for a Size variable? I have tried many different ways
but none of them have worked.

Thanks

Dan
 
You can convert the points to sizes and then use Size subtraction, but
have to deal with issues like did they drag from top/left to
bottom/right or reverse.

I think easiest is to just perform math separately and then create a
size structure from that:

height = Math.Abs(mousedownPoint.X - mouseupPoint.X);
width = Math.Abs(mousedownPoint.Y - mouseupPoint.Y);

Size sz = new Size(width, height);

Unless you want the sizes to be negative which is possible depending
on what you're going to do with the data...

HTH,

Sam
 
Thanks, Sam.

Samuel R. Neff said:
You can convert the points to sizes and then use Size subtraction, but
have to deal with issues like did they drag from top/left to
bottom/right or reverse.

I think easiest is to just perform math separately and then create a
size structure from that:

height = Math.Abs(mousedownPoint.X - mouseupPoint.X);
width = Math.Abs(mousedownPoint.Y - mouseupPoint.Y);

Size sz = new Size(width, height);

Unless you want the sizes to be negative which is possible depending
on what you're going to do with the data...

HTH,

Sam

------------------------------------------------------------
We're hiring! B-Line Medical is seeking .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top