Page 1 of 1

How to measure form locations

Posted: Tue Mar 15, 2011 3:33 pm
by froza
The subject might not be easy to understand, but let's take an example, you're application have 2 forms, and you wanted both the forms to stick together at anywhere, anytime, so one of the form must be a reference point to the other form.
I wanted the 2nd form to be on the top left of the 1st form(reference point), so to calculate the location for the 2nd form will be like the following formula :
Code: Select all
Form1.Location.X - Form1.size.width, Form1.Location.Y - Form1.size.height
In order to calculate other locations, here's the explanation to the formula :
Form1.Location.X - Form1.size.width = Left
Form1.Location.X + Form1.size.width = Right
Form1.Location.Y + Form1.size.height = Bottom
Form1.Location.Y - Form1.size.height = Top
Here, I've pre-calculated some of the basic locations :
bottom left :
Code: Select all
Form1.Location.X - Form1.size.width, Form1.Location.Y + Form1.size.height
bottom right :
Code: Select all
Form1.Location.X + Form1.size.width, Form1.Location.Y + Form1.size.height
top left :
Code: Select all
Form1.Location.X - Form1.size.width, Form1.Location.Y - Form1.size.height
top right :
Code: Select all
Form1.Location.X + Form1.size.width, Form1.Location.Y - Form1.size.height

Re: How to measure form locations

Posted: Tue Mar 15, 2011 3:38 pm
by MrAksel
Very nice tutorial, this is a cool thing to have in every program! Great work and welcome to the site!