Expand mobile version menu

Artificial Intelligence Specialist

Real-Life Activities

Real-Life Math -- Solution

In computer programming, the origin of the coordinates is the top left of the screen. So in order to center the dialog box, you must calculate how far down from the top left corner the dialog box must be placed. Then you must figure out how far right from the left part of the screen the dialog box must be placed. The formulas are as follows:

First, you calculate the top position:

top = (screen height / 2) - (form height / 2)
top = (768 / 2) - (500 / 2)
top = 384 - 250
top = 134

Now, calculate the left position:

left = (screen width / 2) - (form width / 2)
left = (1024 / 2) - (500 / 2)
left = 512 - 250
left = 262

Now that we have the calculations, we realize that in order to center the dialog box on the screen, we need to place the top of the box 134 pixels from the top and 262 pixels from the left.