Propiedades de los campos de entrada: alineación de texto y sólo lectura

Para los objetos de tipo OBJ_EDIT (campo de entrada), un programa MQL puede establecer dos propiedades específicas definidas mediante las funciones ObjectSetInteger/ObjectGetInteger.

Identificador

Descripción

Tipo de valor

OBJPROP_ALIGN

Alineación horizontal del texto

ENUM_ALIGN_MODE

OBJPROP_READONLY

Posibilidad de editar texto

bool

La enumeración ENUM_ALIGN_MODE contiene los siguientes miembros:

Identificador

Descripción

ALIGN_LEFT

Alineación a la izquierda

ALIGN_CENTER

Alineación central

ALIGN_RIGHT

Alineación a la derecha

Tenga en cuenta que, a diferencia de los objetos OBJ_TEXT y OBJ_LABEL, el campo de entrada no se redimensiona automáticamente para ajustarse al texto introducido, por lo que para cadenas largas, puede que necesite establecer explícitamente la propiedad OBJPROP_XSIZE.

En el modo de edición, el desplazamiento horizontal del texto funciona dentro del campo de entrada.

El script ObjectEdit.mq5 crea cuatro objetos OBJ_EDIT: tres de ellos son editables con diferentes métodos de alineación de texto y el cuarto está en modo de sólo lectura.

#include "ObjectPrefix.mqh"
   
void SetupEdit(const int xconst int yconst int dxconst int dy,
   const ENUM_ALIGN_MODE alignment = ALIGN_LEFTconst bool readonly = false)
{
   // create an object with a description of the properties
   const string props = EnumToString(alignment)
      + (readonly ? " read-only" : " editable");
   const string name = ObjNamePrefix + "Edit" + props;
   ObjectCreate(0nameOBJ_EDIT000);
   // position and size
   ObjectSetInteger(0nameOBJPROP_XDISTANCEx);
   ObjectSetInteger(0nameOBJPROP_YDISTANCEy);
   ObjectSetInteger(0nameOBJPROP_XSIZEdx);
   ObjectSetInteger(0nameOBJPROP_YSIZEdy);
   // specific properties of input fields
   ObjectSetInteger(0nameOBJPROP_ALIGNalignment);
   ObjectSetInteger(0nameOBJPROP_READONLYreadonly);
   // colors (different depending on editability)
   ObjectSetInteger(0nameOBJPROP_BGCOLORclrWhite);
   ObjectSetInteger(0nameOBJPROP_COLORreadonly ? clrRed : clrBlue);
   // content
   ObjectSetString(0nameOBJPROP_TEXTprops);
   // tooltip for editable
   ObjectSetString(0nameOBJPROP_TOOLTIP,
      (readonly ? "\n" : "Click me to edit"));
}
   
void OnStart()
{
   SetupEdit(10010020020);
   SetupEdit(10012020020ALIGN_RIGHT);
   SetupEdit(10014020020ALIGN_CENTER);
   SetupEdit(10016020020ALIGN_CENTERtrue);
}

El resultado del script se muestra en la siguiente imagen:

Campos de entrada en diferentes modos

Campos de entrada en diferentes modos

Puede hacer clic en cualquier campo editable y cambiar su contenido.