How to create a Moveable Button

 

Hi guys, 


I know this is possible, but i cant figure it out. I want to click on a button to select it, and whilst it's selected, be able to move it on the Y axis. In this code example, i'm able to move it when the left button is held down, but that's regardless of it being selected or not. i.e. it moves whenever the left mouse button is held down, which is expected. 

#include <ChartObjects\ChartObject.mqh>
#include <Controls\Button.mqh>

CButton    Button123;

bool   MouseDown = false;

//--------------------------------------------------------------------
int OnInit()
  {
  
   string name="TestBut";
   Button123.Create(0, name, 0, 0,0,0,0);
   ObjectSetInteger(0, name, OBJPROP_BGCOLOR,  clrWhite);
   ObjectSetInteger(0, name, OBJPROP_XDISTANCE,100);
   ObjectSetInteger(0, name, OBJPROP_YDISTANCE,100);
   ObjectSetInteger(0, name, OBJPROP_XSIZE,    50);
   ObjectSetInteger(0, name, OBJPROP_YSIZE,    50);
   ObjectSetInteger(0, name, OBJPROP_ZORDER,   0);  
  
   return ChartSetInteger( 0, CHART_EVENT_MOUSE_MOVE, true )
      ? INIT_SUCCEEDED : INIT_FAILED;

  }
void OnDeinit(const int reason)
  {
//---
   
  }

void OnChartEvent(const int id,         // event ID  
                  const long& lparam,   // event parameter of the long type
                  const double& dparam, // event parameter of the double type
                  const string& sparam) // event parameter of the string type
  {
   
   if(id==CHARTEVENT_MOUSE_MOVE)
   { 

      
   if(MouseLeftButtonState((uint)sparam) == "DN") 
      {
         ChartRedraw();  
         Button123.Move(1550, dparam); 
      }
   }
   
  }

string MouseLeftButtonState(uint state) {
   string res;
   res+=(((state& 1)== 1)?"DN":"UP");   // mouse left
   return(res);
}

void OnTick()
  {
//---
   
  }
//+------------------------------------------------------------------+

How do i go about moving the button only when it's selected?

Many Thanks,