Method for aligning two controls when doing interface

xiaoxiao2021-03-06  57

Everyone knows that the size used in the VC interface editor is not a pixel. I don't know how I come. In short, one unit in the interface programmer is not equal to 1 pixel. There is a proportion between them. This ratio is not The integer is a floating point, and the accuracy is still high! I don't know why VC is doing this, but since others have done this, we only have to solve the problem, and the problems that appear are as follows, and several examples:

Only the above problems are said, the same level. One: Two controls, such as Group Box, if they are not aligned, then maybe their bottom is not aligned, such as 1 pixel on the bottom of them, that is, this is like this, because your mobile control is also good, increase or decrease control The height is also good, their steps are 1 unit of the editor, and this 1 unit is more than 1 pixel.

2: Two list boxes (Report) If the last item is completely displayed, then another list box (if they are not equal), it is very difficult to make the last one just completely displayed. of.

Of course, I don't have absolutely unable to solve it. For example, it can increase the height difference of the two controls. When the height is large to a certain extent, this ratio causes the error naturally to the starting point, so that it is, for example Said that the two list boxes I am using, a high 111, a high 172 (all editor units, 9th Song), their last width is just the same.

The above method is of course very unsatisfactory, because I don't know how much is it, I only have exhaustion to find a dismantling point, and since it is interface programming, take the above example, if the interface requires the first list box high 111, The second thing to be greater than 111 and small 172, there is no way to make the last item you have equal!

Since it is not possible to achieve absolute alignment through the interface programmer, then only other methods, it is good to provide MoveWindow in the MFC, which may also be the use of relatively rough position positioning methods in the VC interface editor. The specific method is to initialize the function, such as the onIndialog function of the dialog, first obtain the window position data of the control to move, and then calculate the moving window position, and finally call MoveWindow, as follows:

CRECT Rect; getdlgitem (iDC_XXXX) -> getWindowRect (Rect); Rect.OffsetRect (0, /- 1); // This is generally positive and negative 1, when it is greater than positive and negative 1, it can be moved by interface programmers, not Here you troubleshoot; getdlgitem (IDC_XXXX) -> MoveWindow (RECT);

转载请注明原文地址:https://www.9cbs.com/read-114171.html

New Post(0)