visual-c++mfccedit

Snapping CSpinButtonCtrl to CEdit?


I set my spin controls as auto buddy / increment integer but it seems I have to manually position the controls next to the edit boxes.

Is there no standard way to get the spin control to snap to the right of the edit control?

According to the docs:

You can specify that a spin button control automatically position itself next to its buddy window.

How?


Solution

  • Assuming you are creating the controls (edit box and spin button) in the Visual Studio Resource Designer, and that the spin button immediately follows the edit box in the tab order (i.e. it was added to the dialog box right after the edit control), then you have to set the "Auto Buddy" property to "True" (as you have done, and you most likely also want the "Set Buddy Integer" to true, as well).

    However, to get the spin button to 'visibly attach' to the edit box, you also need to set the "Alignment" property (normally shown at the top of the "Behaviour" property group). Most often, you will probably want "Right Align" (to set the position of the spin to the right of the edit box) but it can also be "Left". The default setting is "Unattached," in which case the position of the spin button will not be changed.

    With either of those alignment positions selected, then it doesn't matter where in the resource template you put the spin control (so long as it is in the correct tab order): it will attach to the right or left side of the edit box when the dialog box is displayed.


    If, like me, you sometimes prefer to edit your resource scripts manually, then the three property settings I mentioned above correspond, respectively, to the UDS_AUTOBUDDY, UDS_SETBUDDYINT and UDS_ALIGNRIGHT (or UDS_ALIGNLEFT) control styles.