Microsoft KB Archive/276554

= INFO: How To Modify a Resize Object to Work with an OptionGroup =

Article ID: 276554

Article Last Modified on 8/27/2002

-

APPLIES TO


 * Microsoft Visual FoxPro 6.0 Professional Edition

-



This article was previously published under Q276554



SUMMARY
If you use the OptionGroup control on a form with the Resize object, the option button group does not resize automatically. This article describes how to make an option button group resize and move with the other controls on the form.



MORE INFORMATION
NOTE: The code in the following set of instructions works for an option button group with either horizontal buttons or vertical buttons, but not both.  Start Visual FoxPro version 6.0. On the File menu, click Open, and then browse to the Vfp98\FFC folder. (This folder is a subfolder of the folder in which Microsoft Visual Studio is installed.) Select the _controls.vcx file. In the Class Name list, click _controls, and then double-click _resizable. In the Properties window, double-click the LoopThroughControls method.  Add Optiongroup to the end of line 11 as follows:   In the Procedure drop-down list box, click SetSize, and then add the following code after the existing code: * Resize Option Group. IF oControl.BaseClass $ &quot;Optiongroup&quot; THEN LOCAL nNumButtons,nLoop, nHorzSpaceBtwnButtons, nVertSpaceBtwnButtons, nButtonHeight, nWidestButton * Initialize Variables. nNumButtons = oControl.ButtonCount nButtonHeight = oControl.Buttons(1).Height && Assume all the buttons are the same height nWidestButton = 0
 * 1) define BASE_CLASS &quot;Commandbutton Combobox Checkbox Listbox Form Grid Textbox Label Shape Editbox Olecontrol Pageframe Image Spinner Optiongroup&quot;

* Find the widest button. FOR nLoop = 1 TO nNumButtons IF (oControl.Buttons(nLoop).Width > nWidestButton) THEN nWidestButton = oControl.Buttons(nLoop).Width ENDIF ENDFOR

* Determine whether the buttons are horizontal or vertical. IF (oControl.Buttons(1).Top != oControl.Buttons(2).Top) THEN lVertical = .T.      && Vertical Buttons ELSE lVertical = .F.      && Horizontal Buttons ENDIF

* Take care of the vertical buttons. IF (lVertical) THEN nVertSpaceBtwnButtons = (oControl.Height - (nNumButtons * nButtonHeight)) / (nNumButtons + 1) FOR nLoop = 1 TO nNumButtons oControl.Buttons(nLoop).Left = (oControl.Width - nWidestButton) / 2 IF nLoop = 1 THEN oControl.Buttons(nLoop).Top = nVertSpaceBtwnButtons ELSE oControl.Buttons(nLoop).Top = (nLoop * nVertSpaceBtwnButtons) + (nButtonHeight * (nLoop - 1)) ENDIF ENDFOR ELSE * Take care of the horizontal buttons. nHorzSpaceBtwnButtons =(oControl.Width   - (nNumButtons * nWidestButton)) / (nNumButtons + 1)

FOR nLoop = 1 TO nNumButtons oControl.Buttons(nLoop).Top = (oControl.Height - nButtonHeight) / 2 IF (nLoop = 1) THEN oControl.Buttons(nLoop).Left = nHorzSpaceBtwnButtons ELSE oControl.Buttons(nLoop).Left = (nLoop * nHorzSpaceBtwnButtons) + (nWidestButton * (nLoop - 1)) ENDIF ENDFOR ENDIF ENDIF  && Optiongroup resize  Save the class.</li> Create a form and place the Resize object on the form.</li>  Add the following code to the Resize event of the form: THISFORM._resizable1.adjustcontrols </li> Add a command button, an option button group, and text box objects to the form.</li> Run the form, and then resize the form. The option button group now moves with the rest of the controls on the form.</li></ol>

<div class="references_section">