Question about OBJ_EDIT

 

Hi coders,

is it somehow possible to delete the text in an OBJ_EDIT when clicking on it? I want to avoid a label as a description for that edit box and so I want to place the description right inside the edit box which should disappear when I click on it.

I tried it this way but it doesn't work:

#property strict
#property indicator_chart_window

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping

   string objName = "testbox";
   ObjectCreate(0, objName, OBJ_EDIT, 0, 0, 0);
   ObjectSetInteger(0, objName, OBJPROP_CORNER, CORNER_RIGHT_UPPER);
   ObjectSetInteger(0, objName, OBJPROP_XDISTANCE, 100);
   ObjectSetInteger(0, objName, OBJPROP_YDISTANCE, 100);
   ObjectSetInteger(0, objName, OBJPROP_XSIZE, 80);
   ObjectSetInteger(0, objName, OBJPROP_YSIZE, 50);
   ObjectSetString(0, objName, OBJPROP_TEXT, "Test");
   ObjectSetInteger(0, objName, OBJPROP_FONTSIZE, 12);
   ObjectSetInteger(0, objName, OBJPROP_ALIGN, ALIGN_CENTER);
   ObjectSetInteger(0, objName, OBJPROP_READONLY, false);
   ObjectSetInteger(0, objName, OBJPROP_COLOR, (color)ChartGetInteger(0, CHART_COLOR_BACKGROUND, 0));
   ObjectSetInteger(0, objName, OBJPROP_BGCOLOR, (color)ChartGetInteger(0, CHART_COLOR_FOREGROUND, 0));
   ObjectSetInteger(0, objName, OBJPROP_BORDER_COLOR, (color)ChartGetInteger(0, CHART_COLOR_BACKGROUND, 0));
   ObjectSetInteger(0, objName, OBJPROP_BACK, true);
   ObjectSetInteger(0, objName, OBJPROP_SELECTABLE, false);
   ObjectSetInteger(0, objName, OBJPROP_SELECTED, false);
   ObjectSetInteger(0, objName, OBJPROP_HIDDEN, true);

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---
   if (id == CHARTEVENT_OBJECT_CLICK) {
      if (ObjectType(sparam)==OBJ_EDIT) {
         ObjectSetString(0, sparam, OBJPROP_TEXT, ""); 
      } 
   }
  }
 

Why not using a tooltip for the info about the edit field?

 
Because I would like to know if this can be done my way. I don't see any logical errors and I am curious why it doesn't work correctly.
 

Change

   ObjectSetInteger(0, objName, OBJPROP_READONLY, false);

to

   ObjectSetInteger(0, objName, OBJPROP_READONLY, true);

if you then want to be able to edit afterwards add in OnChartEvent

   if (id == CHARTEVENT_OBJECT_CLICK) {
      if (ObjectType(sparam)==OBJ_EDIT) {
         ObjectSetString(0, sparam, OBJPROP_TEXT, "");
         ObjectSetInteger(0, sparam, OBJPROP_READONLY, false); 
      } 

.

 

Thanks, half the issue is solved! :)

By the way, can you explain me why I need to set it to read-only first?

Now the edit field is clear but it is not active. Is there another object property to activate it which I don't know yet?


Edit: I just noticed it works with a double click. Any chance to active it by a single click? 

 
mar:

By the way, can you explain me why I need to set it to read-only first?


I think that it has something to do with the box expecting an input.

Now the edit field is clear but it is not active. Is there another object property to activate it which I don't know yet?

The additional line in OnChartEvent does that.