CommandButton (Control)

Crea un botón de comando sencillo.

CommandButton

Observaciones

Los botones de comando suelen emplearse para iniciar un evento que lleva a cabo una acción, como cerrar un formulario, moverse a otro registro, imprimir un informe, etc. Utilice el control CommandGroup para crear un conjunto de botones de comando que pueden manipularse individualmente o como grupo.

Utilice la propiedad Caption para especificar el texto que aparece en un botón de comando. Utilice la propiedad Picture para especificar una imagen para un botón de comando.

Puede elegir un botón de comando al hacer clic en él y si está establecida la propiedad Default en el valor verdadero (.T.), al presionar la tecla ENTRAR cuando está seleccionado el botón de comando. Si la propiedad Cancel del botón de comando se establece en el valor verdadero (.T.), puede elegir el botón de comando al presionar la tecla ESC.

Si desea información adicional acerca de los botones de comando, vea Diseñador de formularios y Usar controles.

Ejemplo

El ejemplo siguiente demuestra cómo puede agregar botones de comando a un formulario. La propiedad Caption se utiliza para especificar el texto de los botones de comando y el texto que indica la secuencia de la tecla de acceso a cada botón. La propiedad Cancel se emplea para especificar un botón que se elige al presionar ESC.

El método AddObject se usa para agregar tres botones de comando al formulario, lo que permite cambiar la dirección en que se inclina un control Line o cerrar el formulario.

frmMyForm = CREATEOBJECT('Form')  && Create a Form
frmMyForm.Closable = .F.  && Disable the Control menu box 

frmMyForm.AddObject('shpLine','Line')  && Add a Line control to the form
frmMyForm.AddObject('cmdCmndBtn1','cmdMyCmndBtn1')  && Up Cmnd button
frmMyForm.AddObject('cmdCmndBtn2','cmdMyCmndBtn2')  && Down Cmnd button
frmMyForm.AddObject('cmdCmndBtn3','cmdMyCmndBtn3')  && Quit Cmnd button

frmMyForm.shpLine.Visible = .T.  && Make Line control visible
frmMyForm.shpLine.Top = 20  && Specify Line control row
frmMyForm.shpLine.Left = 125  && Specify Line control column

frmMyForm.cmdCmndBtn1.Visible =.T.  && Up Command button visible
frmMyForm.cmdCmndBtn2.Visible =.T.  && Down" Command button visible
frmMyForm.cmdCmndBtn3.Visible =.T.  && Quit Command button visible

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

DEFINE CLASS cmdMyCmndBtn1 AS CommandButton  && Create Command button
   Caption = 'Slant \<Up'  && Caption on the Command button
   Left = 50  && Command button column
   Top = 100  && Command button row
   Height = 25  && Command button height
   
   PROCEDURE Click
      ThisForm.shpLine.Visible = .F.  && Hide the Line control
      ThisForm.shpLine.LineSlant ='/'  && Slant up
      ThisForm.shpLine.Visible = .T.  && Show the Line control
ENDDEFINE

DEFINE CLASS cmdMyCmndBtn2 AS CommandButton  && Create Command button
   Caption = 'Slant \<Down'  && Caption on the Command button
   Left = 200  && Command button column
   Top = 100  && Command button row
   Height = 25  && Command button height

   PROCEDURE Click
      ThisForm.shpLine.Visible = .F.  && Hide the Line control
      ThisForm.shpLine.LineSlant ='\'  && Slant down
      ThisForm.shpLine.Visible = .T.  && Show the Line control
ENDDEFINE

DEFINE CLASS cmdMyCmndBtn3 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 = 150  && Command button row
   Height = 25  && Command button height

   PROCEDURE Click
      CLEAR EVENTS  && Stop event processing, close Form
ENDDEFINE

Vea también

CommandButton (Control: propiedades, métodos y eventos) | CommandGroup (Control) | CREATE CLASS | CREATE FORM | DEFINE CLASS