Your question is more about math than programming. But since one without the other does not work, I will sign in detail.
Go. The position of the control on the form and the form on the screen is set by the position of the upper left corner and the Control.Location property (the red dot in the figure below). The position of the remaining angles can be calculated by adding the length and / or width of the control, which is specified in the Control.Size property, to the Control.Location coordinates.

So that the control always remains entirely within the boundaries of the parent control (the form is also control), the coordinate values Control.Location should not go beyond the boundary of the green area in the figure. The dimensions of this area are easy to calculate from the dimensions of the control and the parent control.
It remains to consider only one moment. The control can have a specific frame style, which is especially important for the form. The Control.Size property sets the external dimensions of the control, so if you use them to determine the available drawing area, then the child control will fall under the frame or header of the form. This is not the result that you want to see. To take into account the dimensions of the controls, frames, headers, etc., the Control.ClientSize property is defined, which contains the actual size of the area available for drawing the child elements (read the captions in the figure carefully).