Partilhar via


OBJTOCLIENT( ) Function

Returns a position or dimension of a control or object relative to its form.

OBJTOCLIENT(ObjectName, nPosition)

Return Values

Numeric

Parameters

  • ObjectName
    Specifies the name of the control or object for which the form position is returned.
  • nPosition
    Specifies which form position or dimension of the control or object is returned. The following table lists the values for nPosition and the corresponding position or dimension returned.
    nPosition Position or dimension
    1 Top
    2 Left
    3 Width
    4 Height

Remarks

OBJTOCLIENT( ) returns the position or dimension of a control or object relative to the client area of the form on which it resides. For example, a control or object can be placed on a page in a page frame, and the page frame is placed on a form. The Top, Left, Width, and Height properties return the position or dimension of a control or object relative to the page on which it is placed. However, you can use OBJTOCLIENT( ) to determine the position or dimension of a control or object relative to the form on which the page is placed.

The value returned by OBJTOCLIENT( ) is in pixels.

Example

The following example uses OBJTOCLIENT( ) to display the positions and dimensions of two check boxes relative to the form they're placed on. The Top, Left, Width, and Height properties are also used to display the positions and dimensions of the two check boxes relative to the page frame on which they're placed.

A command button and a page frame are placed on a form. The PageCount property is used to specify the number of pages on the page frame. The Tabs property is set to true (.T.) to specify that the page frame has tabs for each page. Check boxes are placed on each page in different positions.

When a check box is clicked, the Click procedure for the check box is executed. If the check box is checked, the Top, Left, Width, and Height properties are used to display the positions and dimensions of the check box relative to the page frame, and OBJTOCLIENT( ) is used to display the positions and dimensions of the check box relative to the form. If the check box is unchecked, the main Microsoft Visual FoxPro window is cleared.

CLEAR
STORE _DBLCLICK TO gnDblClick  && Save double-click value
STORE 0.05 TO _DBLCLICK  && Make double-click unlikely

frmMyForm = CREATEOBJECT('Form')  && Create a form
frmMyForm.Closable = .f.  && Disable the window pop-up menu
 
frmMyForm.Move(150,10)  && Move the form

frmMyForm.AddObject('cmbCommand1','cmdMyCmdBtn')  && Add Command button
frmMyForm.AddObject('pgfPageFrame1','pgfMyPageFrame')  && Add PageFrame
frmMyForm.pgfPageFrame1.Page1.AddObject('chkCheckBox1','chkMyCheckBox1')
frmMyForm.pgfPageFrame1.Page2.AddObject('chkCheckBox2','chkMyCheckBox2')

frmMyForm.cmbCommand1.Visible =.T.  && "Quit" Command button visible
frmMyForm.pgfPageFrame1.Visible =.T.  && PageFrame visible
frmMyForm.pgfPageFrame1.Page1.chkCheckBox1.Visible =.T.
frmMyForm.pgfPageFrame1.Page2.chkCheckBox2.Visible =.T.

frmMyForm.SHOW  && Display the form
READ EVENTS  && Start event processing

DEFINE CLASS cmdMyCmdBtn AS CommandButton  && Create Command button
   Caption = '\<Quit'  && Caption on the Command button
   Cancel = .T.  && Default Cancel Command button (Esc)
   Left = 125  && Command button column
   Top = 210  && Command button row
   Height = 25  && Command button height

   PROCEDURE Click
      CLEAR EVENTS  && Stop event processing, close Form
      CLEAR  && Clear main Visual FoxPro window
      STORE gnDblClick TO _DBLCLICK  && Restore double-click value
ENDDEFINE

DEFINE CLASS pgfMyPageFrame AS PageFrame  && Create PageFrame
   Left = 10  && PageFrame  column
   Top = 10  && PageFrame  row
   Height = 175  && PageFrame  height
   Width = 350  && PageFrame  height
   PageCount = 2  && 2 Pages on the PageFrame
   Tabs = .T.  && Tabs visible
ENDDEFINE

DEFINE CLASS chkMyCheckBox1 AS CheckBox  && Create first Check Box
   Top = 0
   Width = 200
   Caption = 'Display Position'

PROCEDURE Click
   DO CASE
      CASE ThisForm.pgfPageFrame1.Page1.chkCheckBox1.Value = 0
         ACTIVATE SCREEN
         CLEAR
      CASE ThisForm.pgfPageFrame1.Page1.chkCheckBox1.Value = 1
         ACTIVATE SCREEN
         CLEAR
         ? 'Positions relative'
         ? 'to PageFrame:'
         ?
         ? 'Top: '
         ?? ALLTRIM(STR;
            (ThisForm.pgfPageFrame1.Page1.chkCheckBox1.Top))
         ? 'Left: '
         ?? ALLTRIM(STR;
            (ThisForm.pgfPageFrame1.Page1.chkCheckBox1.Left))
         ? 'Width: '
         ?? ALLTRIM(STR;
            (ThisForm.pgfPageFrame1.Page1.chkCheckBox1.Width))
         ? 'Height: '
         ?? ALLTRIM(STR;
            (ThisForm.pgfPageFrame1.Page1.chkCheckBox1.Height))
         ?
         ? 'Positions relative'
         ? 'to Form:'
         ?
         ? 'Top: '
         ?? ALLTRIM(STR(OBJTOCLIENT;
            (ThisForm.pgfPageFrame1.Page1.chkCheckBox1,1)))
         ? 'Left: '
         ?? ALLTRIM(STR(OBJTOCLIENT;
            (ThisForm.pgfPageFrame1.Page1.chkCheckBox1,2)))
         ? 'Width: '
         ?? ALLTRIM(STR(OBJTOCLIENT;
            (ThisForm.pgfPageFrame1.Page1.chkCheckBox1,3)))
         ? 'Height: '
         ?? ALLTRIM(STR(OBJTOCLIENT(ThisForm.pgfPageFrame1.Page1.chkCheckBox1,4)))
   ENDCASE
ENDDEFINE

DEFINE CLASS chkMyCheckBox2 AS CheckBox  && Create second Check Box
   Top = 30
   Left = 175
   Width = 200
   Caption = 'Display Position'

PROCEDURE CLICK
   DO CASE
      CASE ThisForm.pgfPageFrame1.Page2.chkCheckBox2.Value = 0
         ACTIVATE SCREEN
         CLEAR
      CASE ThisForm.pgfPageFrame1.Page2.chkCheckBox2.Value = 1
         ACTIVATE SCREEN
         CLEAR
         ? 'Positions relative'
         ? 'to PageFrame:'
         ?
         ? 'Top: '
         ?? ALLTRIM(STR(ThisForm.pgfPageFrame1.Page2.chkCheckBox2.Top))
         ? 'Left: '
         ?? ALLTRIM(STR;
            (ThisForm.pgfPageFrame1.Page2.chkCheckBox2.Left))
         ? 'Width: '
         ?? ALLTRIM(STR;
            (ThisForm.pgfPageFrame1.Page2.chkCheckBox2.Width))
         ? 'Height: '
         ?? ALLTRIM(STR;
            (ThisForm.pgfPageFrame1.Page2.chkCheckBox2.Height))
         
         ?
         ? 'Positions relative'
         ? 'to Form:'
         ?
         ? 'Top: '
         ?? ALLTRIM(STR(OBJTOCLIENT;
            (ThisForm.pgfPageFrame1.Page2.chkCheckBox2,1)))
         ? 'Left: '
         ?? ALLTRIM(STR(OBJTOCLIENT;
            (ThisForm.pgfPageFrame1.Page2.chkCheckBox2,2)))
         ? 'Width: '
         ?? ALLTRIM(STR(OBJTOCLIENT;
            (ThisForm.pgfPageFrame1.Page2.chkCheckBox2,3)))
         ? 'Height: '
         ?? ALLTRIM(STR(OBJTOCLIENT;
            (ThisForm.pgfPageFrame1.Page2.chkCheckBox2,4)))
   ENDCASE
ENDDEFINE

See Also

Height Property | Left Property | Top Property | Width Property