OBJ_BUTTON

Oggetto bottone.

ObjButton

Nota

Le coordinate del punto di ancoraggio sono impostate in pixels. È possibile selezionare l'angolo di ancoraggio del bottone da ENUM_BASE_CORNER.

Esempio

The following script creates and moves Button object on the chart. Funzioni speciali sono state sviluppate per creare e modificare le proprietà dell'oggetto grafico. È possibile utilizzare queste funzioni "come è" nelle proprie applicazioni.

//--- descrizione
#property description "Lo Script crea il bottone sul chart."
//--- mostra la finestra dei parametri di input durante il lancio dello script
#property script_show_inputs
//--- parametri di input dello script
input string           InpName="Button";            // Nome bottone
input ENUM_BASE_CORNER InpCorner=CORNER_LEFT_UPPER// Angolo del chart per l'ancoraggio
input string           InpFont="Arial";             // Font
input int              InpFontSize=14;              // Grandezza Font
input color            InpColor=clrBlack;           // Colore del testo
input color            InpBackColor=C'236,233,216'// Colore sottofondo
input color            InpBorderColor=clrNONE;      // Colore bordo
input bool             InpState=false;              // Premuto/Rilasciato
input bool             InpBack=false;               // Oggetto sottofondo
input bool             InpSelection=false;          // Evidenzia movimento
input bool             InpHidden=true;              // Nascosto nella lista oggetti
input long             InpZOrder=0;                 // Priorità per il click del mouse
//+--------------------------------------------------------------------------------+
//| Crea il bottone                                                                |
//+--------------------------------------------------------------------------------+
bool ButtonCreate(const long              chart_ID=0,               // ID del chart
                  const string            name="Button",            // nome del bottone
                  const int               sub_window=0,             // indice sottofinestra
                  const int               x=0,                      // coordinate X
                  const int               y=0,                      // coordinate Y
                  const int               width=50,                 // spessore bottone
                  const int               height=18,                // altezza bottone
                  const ENUM_BASE_CORNER  corner=CORNER_LEFT_UPPER// angolo del chart per l'ancoraggio
                  const string            text="Button",            // testo
                  const string            font="Arial",             // font
                  const int               font_size=10,             // grandezza font
                  const color             clr=clrBlack,             // colore del testo color
                  const color             back_clr=C'236,233,216',  // coloredi sottofondo
                  const color             border_clr=clrNONE,       // colore del bordo
                  const bool              state=false,              // premuto/rilasciato
                  const bool              back=false,               // in sottofondo
                  const bool              selection=false,          // evidenzia moviemento
                  const bool              hidden=true,              // nascosto nella lista oggetti
                  const long              z_order=0)                // priorità per il click del mouse
  {
//--- resetta il valore dell' errore
   ResetLastError();
//--- crea il bottone
   if(!ObjectCreate(chart_ID,name,OBJ_BUTTON,sub_window,0,0))
     {
      Print(__FUNCTION__,
            ": fallimento nel creare il bottone! Error code = ",GetLastError());
      return(false);
     }
//--- imposta coordinate bottone
   ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);
   ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);
//--- imposta grandezza bottone
   ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width);
   ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height);
//--- imposta l'angolo del chart, relativo a quali punti coordinate vengono definiti
   ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner);
//--- imposta il testo
   ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);
//--- imposta il font
   ObjectSetString(chart_ID,name,OBJPROP_FONT,font);
//--- imposta grandezza font
   ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);
//--- set text color
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//--- imposta colore di background
   ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,back_clr);
//--- imposta colore del bordo
   ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_COLOR,border_clr);
//--- mostra in primo piano (false) o sottofondo (true)
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
//--- set button state
   ObjectSetInteger(chart_ID,name,OBJPROP_STATE,state);
//--- abilita (true) o disabilita (false) la modalità di movimento del bottone con il mouse
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
//--- nascondi (true) o mostra (falso) il nome di oggetto grafico nella lista degli oggetti
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
//--- imposta la priorità per ricevere l'evento di un clic del mouse nel grafico
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
//--- esecuzione avvenuta
   return(true);
  }
//+--------------------------------------------------------------------------------+
//| Sposta il bottone                                                              |
//+--------------------------------------------------------------------------------+
bool ButtonMove(const long   chart_ID=0,    // ID del chart
                const string name="Button"// nome del bottone
                const int    x=0,           // coordinate X
                const int    y=0)           // coordinate Y
  {
//--- resetta il valore dell' errore
   ResetLastError();
//--- sposta il bottone
   if(!ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x))
     {
      Print(__FUNCTION__,
            ": fallimento nello spostamento delle coordinate X del bottone! Error code = ",GetLastError());
      return(false);
     }
   if(!ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y))
     {
      Print(__FUNCTION__,
            ": fallimento nello spostamento delle coordinate Y del bottone! Error code = ",GetLastError());
      return(false);
     }
//--- esecuzione avvenuta
   return(true);
  }
//+--------------------------------------------------------------------------------+
//| Cambia la grandezza del bottone                                                |
//+--------------------------------------------------------------------------------+
bool ButtonChangeSize(const long   chart_ID=0,    // ID del chart
                      const string name="Button"// nome del bottone
                      const int    width=50,      // spesso del bottone
                      const int    height=18)     // altezza del bottone
  {
//--- resetta il valore dell' errore
   ResetLastError();
//--- cambia la grandezza del bottone
   if(!ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width))
     {
      Print(__FUNCTION__,
            ": fallimento nel cambiare lo spessore del bottone! Error code = ",GetLastError());
      return(false);
     }
   if(!ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height))
     {
      Print(__FUNCTION__,
            ": fallimento nel cambiare l'altezza del bottone! Error code = ",GetLastError());
      return(false);
     }
//--- esecuzione avvenuta
   return(true);
  }
//+--------------------------------------------------------------------------------+
//| Cambia l'angolo del chart per collegare il bottone                             |
//+--------------------------------------------------------------------------------+
bool ButtonChangeCorner(const long             chart_ID=0,               // ID del chart
                        const string           name="Button",            // nome del bottone
                        const ENUM_BASE_CORNER corner=CORNER_LEFT_UPPER// angolo del chart per l'ancoraggio
  {
//--- resetta il valore dell' errore
   ResetLastError();
//--- cambia l'angolo di ancoraggio
   if(!ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner))
     {
      Print(__FUNCTION__,
            ": fallimento nel cambiare l'angolo di ancoraggio! Error code = ",GetLastError());
      return(false);
     }
//--- esecuzione avvenuta
   return(true);
  }
//+--------------------------------------------------------------------------------+
//| Cambia il testo del bottone                                                    |
//+--------------------------------------------------------------------------------+
bool ButtonTextChange(const long   chart_ID=0,    // ID del chart
                      const string name="Button"// nome del bottone
                      const string text="Text")   // testo
  {
//--- resetta il valore dell' errore
   ResetLastError();
//--- cambia il testo dell'oggetto
   if(!ObjectSetString(chart_ID,name,OBJPROP_TEXT,text))
     {
      Print(__FUNCTION__,
            ": fallimento nel cambiare il testo! Error code = ",GetLastError());
      return(false);
     }
//--- esecuzione avvenuta
   return(true);
  }
//+--------------------------------------------------------------------------------+
//| Elimina il bottone                                                             |
//+--------------------------------------------------------------------------------+
bool ButtonDelete(const long   chart_ID=0,    // ID del chart
                  const string name="Button"// nome del bottone
  {
//--- resetta il valore dell' errore
   ResetLastError();
//--- elimina il bottone
   if(!ObjectDelete(chart_ID,name))
     {
      Print(__FUNCTION__,
            ": fallimento nell'eliminare il bottone! Error code = ",GetLastError());
      return(false);
     }
//--- esecuzione avvenuta
   return(true);
  }
//+--------------------------------------------------------------------------------+
//| Funzione di avvio del programma Script                                         |
//+--------------------------------------------------------------------------------+
voidOnStart()
  {
//--- grandezza della finestra chart
   long x_distance;
   long y_distance;
//--- imposta la grandezza della finestra
   if(!ChartGetInteger(0,CHART_WIDTH_IN_PIXELS,0,x_distance))
     {
      Print("Fallimento nell'ottenere la grandezza del chart! Error code = ",GetLastError());
      return;
     }
   if(!ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS,0,y_distance))
     {
      Print("Fallimento nell'ottenere l'altezza del chart! Error code = ",GetLastError());
      return;
     }
//--- definisce lo step per il cambio della grandezza del bottone
   int x_step=(int)x_distance/32;
   int y_step=(int)y_distance/32;
//--- imposta le coordinate del bottone e la sua grandezza
   int x=(int)x_distance/32;
   int y=(int)y_distance/32;
   int x_size=(int)x_distance*15/16;
   int y_size=(int)y_distance*15/16;
//--- crea il bottone
   if(!ButtonCreate(0,InpName,0,x,y,x_size,y_size,InpCorner,"Press",InpFont,InpFontSize,
      InpColor,InpBackColor,InpBorderColor,InpState,InpBack,InpSelection,InpHidden,InpZOrder))
     {
      return;
     }
//--- redisegna il chart
   ChartRedraw();
//--- riduce il bottone nel loop
   int i=0;
   while(i<13)
     {
      //--- ritardo di mezzo secondo
      Sleep(500);
      //--- commuta il bottone allo stato premuto
      ObjectSetInteger(0,InpName,OBJPROP_STATE,true);
      //--- ridisegna il chart ed aspetta 0.2 secondi
      ChartRedraw();
      Sleep(200);
      //--- ridefinisce le coordinate e la grandezza del bottone
      x+=x_step;
      y+=y_step;
      x_size-=x_step*2;
      y_size-=y_step*2;
      //--- riduce il bottone
      ButtonMove(0,InpName,x,y);
      ButtonChangeSize(0,InpName,x_size,y_size);
      //--- riporta indietro lo stato del bottone a rilasciato
      ObjectSetInteger(0,InpName,OBJPROP_STATE,false);
      //--- ridisegna il chart
      ChartRedraw();
      //--- controlla se l'operazione dello script è stata disabilitata per forza
      if(IsStopped())
         return;
      //--- incrementa il contatore del loop
      i++;
     }
//--- ritardo di mezzo secondo
   Sleep(500);
//--- elimina il bottone
   ButtonDelete(0,InpName);
   ChartRedraw();
//--- aspetta per 1 secondo
   Sleep(1000);
//---
  }