Condividi tramite


Click Event

Occurs when you include code in a program that triggers the event, when the user clicks a control, changes the value of certain controls, or clicks in a blank area of a form.

PROCEDURE Object.Click

Remarks

Applies To: CheckBox Control | ComboBox Control | CommandButton Control | CommandGroup Control | Container Object | Control Object | EditBox Control | Form Object | Grid Control | Header Object | Image Control | Label Control | Line Control | ListBox Control | OptionButton Control | OptionGroup Control | Page Object | PageFrame Control | Shape Control | Spinner Control | TextBox Control | ToolBar Object

The Click event occurs when the user:

  • Clicks a check box, command button, combo box, list box, or option button with the left mouse button.

  • Presses the SPACEBAR when a command button, option button, or check box has the focus.

  • Presses ENTER when a form has a command button with its Default property set to True (.T.).

  • Presses the access key for a control. For example, if the caption of a command button is "\<Go", pressing ALT+G triggers the Click event.

  • Clicks a blank area of a form. Click events on a form do not occur when the pointer is over the title bar, the Window menu icon, or the window borders.

  • Clicks the text entry area of a spinner.

  • Clicks a disabled control. The Click event occurs for the container on which the disabled control is placed.

The Click event also occurs as a result of code you include that issues the MOUSE command.

Note

Resizing grid column headers does not trigger the Click event for the column header. This affects column separators.

Example

The following example creates an OptionGroup control and places the control on a form. The OptionGroup control has three buttons, and depending on the option button you click, a circle, ellipse, or square appears. The ButtonCount property is used to specify the number of buttons in the OptionGroup. The Buttons and Caption properties are used to specify the text displayed next to each option button.

The Shape control is used to create the circle, ellipse, and square. The OptionGroup control's Click event uses a DO CASE ... ENDCASE structure and the Value property to display the appropriate shape when you click an option button.

frmMyForm = CREATEOBJECT('Form')  && Create a Form
frmMyForm.Closable = .F.  && Disable the window pop-up menu

frmMyForm.AddObject('cmdCommand1','cmdMyCmndBtn')  && Add Command button
frmMyForm.AddObject('opgOptionGroup1','opgMyOptGrp') && Add Option Group
frmMyForm.AddObject('shpCircle1','shpMyCircle')  && Add Circle Shape
frmMyForm.AddObject('shpEllipse1','shpMyEllipse')  && Add Ellipse Shape
frmMyForm.AddObject('shpSquare','shpMySquare')  && Add Box Shape

frmMyForm.cmdCommand1.Visible =.T.  && "Quit" Command button visible

frmMyForm.opgOptionGroup1.Buttons(1).Caption = "\<Circle"
frmMyForm.opgOptionGroup1.Buttons(2).Caption = "\<Ellipse"
frmMyForm.opgOptionGroup1.Buttons(3).Caption = "\<Square"
frmMyForm.opgOptionGroup1.SetAll("Width", 100) && Set Option group width
frmMyForm.opgOptionGroup1.Visible = .T.  && Option Group visible
frmMyForm.opgOptionGroup1.Click  && Show the circle

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

DEFINE CLASS opgMyOptGrp AS OptionGroup  && Create an Option Group
   ButtonCount = 3  && Three Option buttons
   Top = 10
   Left = 10
   Height = 75
   Width = 100

   PROCEDURE Click 
      ThisForm.shpCircle1.Visible = .F.  && Hide the circle
      ThisForm.shpEllipse1.Visible = .F.  && Hide the ellipse
      ThisForm.shpSquare.Visible = .F.  && Hide the square
      
      DO CASE
         CASE ThisForm.opgOptionGroup1.Value = 1
            ThisForm.shpCircle1.Visible = .T. && Show the circle
         CASE ThisForm.opgOptionGroup1.Value = 2 
            ThisForm.shpEllipse1.Visible = .T.  && Show the ellipse
         CASE ThisForm.opgOptionGroup1.Value = 3 
            ThisForm.shpSquare.Visible = .T.  && Show the square
      ENDCASE
ENDDEFINE

DEFINE CLASS cmdMyCmndBtn 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
ENDDEFINE

DEFINE CLASS shpMyCircle AS SHAPE  && Create a circle
   Top = 10
   Left = 200
   Width = 100
   Height = 100
   Curvature = 99
   BackColor = RGB(255,0,0)  && Red
ENDDEFINE

DEFINE CLASS shpMyEllipse AS SHAPE  && Create an ellipse
   Top = 35
   Left = 200
   Width = 100
   Height = 50
   Curvature = 99
   BackColor = RGB(0,128,0)  && Green
ENDDEFINE

DEFINE CLASS shpMySquare AS SHAPE  && Create a square
   Top = 10
   Left = 200
   Width = 100
   Height = 100
   Curvature = 0
   BackColor = RGB(0,0,255)  && Blue
ENDDEFINE

See Also

Reference

DblClick Event

MiddleClick Event

MOUSE Command

MouseDown Event

MouseUp Event

MouseWheel Event

Value Property

Other Resources

Events (Visual FoxPro)