Microsoft KB Archive/131081

= How to Set Object's BackColor to Button Face's BackColor =

Article ID: 131081

Article Last Modified on 2/15/2000

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition

-



This article was previously published under Q131081



SUMMARY
This article shows by example how to set the BackColor of an object to the current button-face color. You can use this in a program to change the BackColor of the form or form page color to match that of the button face or 3D color.



Step-by-Step Example Using Code
The following program displays a form that contains one command button (Button1). The code in the Click procedure sets the BackColor of the form to the current BackColor of the button face.

 From the File menu, choose New. Select the Program option, and choose the New File button to bring up the Modify Program window.  Enter the following code: oMyForm = CREATEOBJECT("MyForm") oMyForm.show READ EVENTS

DEFINE CLASS MyForm AS FORM

ADD OBJECT Button1 AS COMMANDBUTTON WITH ; caption="QUIT"

PROCEDURE Click Local cColor cRGB m.cRGB = RGBSCHEME(1,2) m.cColor = 'RGB(' + SUBSTR(m.cRGB, AT(',', m.cRGB, 3) +1)        This.BackColor = EVAL(cColor)      ENDPROC

PROCEDURE button1.Click CLEAR EVENTS ENDPROC ENDDEFINE  Save the Program, and run it. When the form displays, click an area of the form to see the BackColor of the form change to the BackColor of the button.

Step-by-Step Example Using the Form Designer
To add this functionality to a Form by using the Visual FoxPro Form Designer, follow these steps:

 Add a command button to the form by using the Form Control Toolbar. Using the secondary (right) mouse button, click the new command button object. Select Properties from the menu that appears. Select the Layout tab in the Properties dialog box. Change the Caption property to QUIT.</li>  Select the Methods tab in the Properties dialog box, and double-click the Click event to open the Code window for the Click Procedure of the command button. In the Code window for the Click event, type: THISFORM.RELEASE NOTE: This code differs from that used in the code example. The command THISFORM.RELEASE is used instead of CLEAR EVENTS because the READ EVENTS is not used to keep the form in memory when DO FORM is used. </li> Using the primary (left) mouse button, double-click the Form to open the Code window for the different events available for the Form.</li>  Select Click from the Procedure list, and add the following code to this Click event: Local cColor cRGB m.cRGB = RGBSCHEME(1,2) m.cColor = 'RGB(' + SUBSTR(m.cRGB, AT(',', m.cRGB, 3) +1)  This.BackColor = EVAL(cColor)                        </li> Save the Form, and run it.</li></ol>

Additional query words: VFoxWin

Keywords: kbcode KB131081

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.