How to measure form locations
Posted: Tue Mar 15, 2011 3:33 pm
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 :
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 :
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
In order to calculate other locations, here's the explanation to the formula :Form1.Location.X - Form1.size.width, Form1.Location.Y - Form1.size.height
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
bottom right :
Form1.Location.X - Form1.size.width, Form1.Location.Y + Form1.size.height
Code: Select all
top left :
Form1.Location.X + Form1.size.width, Form1.Location.Y + Form1.size.height
Code: Select all
top right :
Form1.Location.X - Form1.size.width, Form1.Location.Y - Form1.size.height
Code: Select all
Form1.Location.X + Form1.size.width, Form1.Location.Y - Form1.size.height