What is the size and coordinate measurement difference in C#Forms

Asked

Viewed 195 times

3

In my project I work with the distance of elements and their size. But on a screen, 600 by 600, when inserting an object, 100 by 100, it appears to be much smaller than 1/6 of the screen, and when checking the distance of the object’s central point to the mouse

//descobrir o ponto central do objeto atual
Point ponto_central_obj = new Point(objeto.Location.X+50,objeto.Location.Y+50);
//calcular distancia X e Y
int distancia_x = ponto.X - ponto_central_obj.X;
int distancia_y = ponto.Y - ponto_central_obj.Y;
if(distancia_x < 0){distancia_x = distancia_x * -1;}
if(distancia_y < 0){distancia_y = distancia_y * -1;}
int distancia = Math.Sqrt((distancia_x ^ 2) + (distancia_y ^ 2));

And when you move the mouse next to the given edge the distance is 15 , 16 or something close, which is much less than 50, which is the minimum distance from the center point to the edge of the object.

Questions

Based on this I ask the following questions.

  • The x and y coordinates are not the distance in pixels top left corner of the screen?

  • If not, how to convert the value to distance in pixels?

  • They are relative according to the size of the parent object?

  • Can you give more details? Show what you have done to reach these conclusions. In principle, without seeing what you have done, I would answer yes to the first question and the third question. Perhaps it is because of this behavior that you are finding something strange. You do not have the entire screen at your disposal. You have the area the object is being added to.

  • And that I’m considering the coordinate as distance in pixels from such a point to the top, in the case of the X coordinate, and distance of pixels to the left corner, in the case of the Y coordinate, I’m right?

  • Yes, that’s it. The X, Y 0.0 stands for the top left of the object container. So if you put any other object inside the Form main which is your window at position 10.20, will be placing on "column" 10 (porting on a horizontal ruler) the useful part of the window and "line" 20 (on a vertical ruler). See if this is all so I can make an answer official. Or clarify if this isn’t what I wanted to know.

1 answer

2


The x and y coordinates are not the pixel distance of the upper-left corner of the screen?

They are relative according to the size of the parent object?

Yes, that’s it. x, y 0.0 means the top left of the object container. So if you place any other object within the main form that is your window at position 10.20 you will be placing on "column" 10 (porting on a horizontal ruler) the useful part of the window (excluding edge for example) and "line" 20 (on a vertical ruler).

Cartesian coordinates are always calculated within the object where another object is being added. So this must be giving the feeling that it’s wrong.

You’re not in a canvas, on a free screen to put what you want, you always have the parent object as "your screen" of the moment.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.