You have to calculate the width according to the available width, the number of controls, and the spacing between the controls and to the borders.
Assuming you have a left and right space to the borders and a space between the controls the width of a single control can be calculated as:
int availWidth = boundingRect.Width();
int numControls = sizeof(rEditPosRightToLeft) / sizeof(rEditPosRightToLeft[0]);
const int borderSpace = 2; const int betweenSpace = 4;
int controlWidth = (availWidth - 2 * borderSpace - (numControls - 1) * betweenSpace) / numControls;
You have also to calculate the left position for each control. It starts at
borderSpace
and must be incremented by
controlWidth + betweenSpace
with each loop iteration. If the above
controlWidth
calculation has a remainder from the final division, you might also get that and use it up while calculating the
x
positions.