controls : How do I disable the chart scroll?

 

https://www.mql5.com/en/docs/standardlibrary/controls/cscrollh 

If I the scrollbar(CScrollH) with the mouse move, move the chart. How do I disable the chart scroll? 


Documentation on MQL5: Standard Library / Classes for Control Panels and Dialogs / CScrollH
Documentation on MQL5: Standard Library / Classes for Control Panels and Dialogs / CScrollH
  • www.mql5.com
Standard Library / Classes for Control Panels and Dialogs / CScrollH - Documentation on MQL5
 
FinGeR:

https://www.mql5.com/en/docs/standardlibrary/controls/cscrollh 

If I the scrollbar(CScrollH) with the mouse move, move the chart. How do I disable the chart scroll? 


Finger, sorry, can you show your scroll code, so I don't have to build it from scratch, I kinda lazy today.

I guess we have to use OnChartEvent's CHARTEVENT_OBJECT_DRAG, but then what to do next ?, Funny MQ does not provide example for this  :(

 

Finger, sorry, can you show your scroll code, so I don't have to build it from scratch, I kinda lazy today. 

 2 files PanelDialog.mqh and PanelIndicator.mq5   

//+------------------------------------------------------------------+
//|                                                  PanelDialog.mqh |
//|                        Copyright 2011, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#include <Controls\Dialog.mqh>
#include <Controls\Panel.mqh>
#include <Controls\Edit.mqh>
#include <Controls\Label.mqh>
#include <Controls\SpinEdit.mqh>
#include <Controls\Scrolls.mqh>

//+------------------------------------------------------------------+
//| defines                                                          |
//+------------------------------------------------------------------+
//--- indents and spacing
#define INDENT_LEFT                         (11)      // left indent (including the border width)
#define INDENT_TOP                          (11)      // top indent (including the border width)
#define INDENT_RIGHT                        (11)      // right indent (including the border width)
#define INDENT_BOTTOM                       (11)      // bottom indent (including the border width)
#define CONTROLS_GAP_X                      (10)      // spacing along the X-axis
#define CONTROLS_GAP_Y                      (10)      // spacing along the Y-axis
//--- for labels
#define LABEL_WIDTH                         (50)      // size along the X-axis
//--- for edits
#define EDIT_WIDTH                          (50)      // size along the X-axis
#define EDIT_HEIGHT                         (20)      // size along the Y-axis
//--- for base colors (RGB)
#define BASE_COLOR_MIN                      (0)       // minimum value of the color component
#define BASE_COLOR_MAX                      (255)     // maximum value of the color component
//+------------------------------------------------------------------+
//| CPanelDialog class                                               |
//| Function: main application dialog                                |
//+------------------------------------------------------------------+
class CPanelDialog : public CAppDialog
  {
private:
   //--- additional controls
   CScrollH          m_scrollh;                       // object for display scroll
   CPanel            m_color;                         // object for displaying color
   CLabel            m_label_red;                     // "red" level caption object
   CEdit             m_field_red;                     // "red" value display object
   CLabel            m_label_green;                   // "green" level caption object
   CEdit             m_field_green;                   // "green" value display object
   CLabel            m_label_blue;                    // "blue" level caption object
   CSpinEdit         m_edit_blue;                     // "blue" value control object
   //--- parameter values
   int               m_red;                           // "red" value
   int               m_green;                         // "green" value
   int               m_blue;                          // "blue" value

public:
                     CPanelDialog(void);
                    ~CPanelDialog(void);
   //--- creation
   virtual bool      Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2);
   //--- chart event handler
   virtual bool      OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam);
   //--- properties
   void              SetRed(const int value);
   void              SetGreen(const int value);
   void              SetBlue(const int value);

protected:
   //--- creating additional controls
   bool              CreateScrollH(void);
   bool              CreateColor(void);
   bool              CreateRed(void);
   bool              CreateGreen(void);
   bool              CreateBlue(void);
   //--- internal event handlers
   virtual bool      OnResize(void);
   //--- event handlers for additional controls
   void              OnChangeBlue(void);
   //--- methods
   void              SetColor(void);
  };
//+------------------------------------------------------------------+
//| Event handling                                                   |
//+------------------------------------------------------------------+
EVENT_MAP_BEGIN(CPanelDialog)
   ON_EVENT(ON_CHANGE,m_edit_blue,OnChangeBlue)
EVENT_MAP_END(CAppDialog)
//+------------------------------------------------------------------+
//| Constructor                                                      |
//+------------------------------------------------------------------+
CPanelDialog::CPanelDialog(void) : m_red((BASE_COLOR_MAX-BASE_COLOR_MIN)/2),
                                   m_green((BASE_COLOR_MAX-BASE_COLOR_MIN)/2),
                                   m_blue((BASE_COLOR_MAX-BASE_COLOR_MIN)/2)
  {
  }
//+------------------------------------------------------------------+
//| Destructor                                                       |
//+------------------------------------------------------------------+
CPanelDialog::~CPanelDialog(void)
  {
  }
//+------------------------------------------------------------------+
//| Creation                                                         |
//+------------------------------------------------------------------+
bool CPanelDialog::Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2)
  {
//--- calling the parent class method
   if(!CAppDialog::Create(chart,name,subwin,x1,y1,x2,y2))                           return(false);
//--- creating additional controls
   //if(!CreateColor())                                                               return(false);
   //if(!CreateRed())                                                                 return(false);
   //if(!CreateGreen())                                                               return(false);
   if(!CreateScrollH())                                                                return(false);
//--- setting the panel color
   SetColor();
//--- success
   return(true);
  }
//+------------------------------------------------------------------+
//| Color panel creation                                             |
//+------------------------------------------------------------------+
bool CPanelDialog::CreateColor(void)
  {
//--- coordinates
   int x1=INDENT_LEFT+LABEL_WIDTH+CONTROLS_GAP_X+EDIT_WIDTH+CONTROLS_GAP_X;
   int y1=INDENT_TOP;
   int x2=ClientAreaWidth()-INDENT_RIGHT;
   int y2=ClientAreaHeight()-INDENT_BOTTOM;
//--- creating
   if(!m_color.Create(m_chart_id,m_name+"Color",m_subwin,x1,y1,x2,y2))              return(false);
   if(!m_color.ColorBorder(CONTROLS_EDIT_COLOR_BORDER))                             return(false);
   if(!Add(m_color))                                                                return(false);
//--- success
   return(true);
  }
//+------------------------------------------------------------------+
//| Creating the display element "Red" with explanatory caption      |
//+------------------------------------------------------------------+
bool CPanelDialog::CreateRed(void)
  {
//--- coordinates
   int x1=INDENT_LEFT;
   int y1=INDENT_TOP;
   int x2=x1+EDIT_WIDTH;
   int y2=y1+EDIT_HEIGHT;
//--- creating the caption
   if(!m_label_red.Create(m_chart_id,m_name+"LabelRed",m_subwin,x1,y1+1,x2,y2))     return(false);
   if(!m_label_red.Text("Red"))                                                     return(false);
   if(!Add(m_label_red))                                                            return(false);
//--- adjusting the coordinates
   x1+=LABEL_WIDTH+CONTROLS_GAP_X;
   x2=x1+EDIT_WIDTH;
//--- creating the display element
   if(!m_field_red.Create(m_chart_id,m_name+"Red",m_subwin,x1,y1,x2,y2))            return(false);
   if(!m_field_red.Text(IntegerToString(m_red)))                                    return(false);
   if(!m_field_red.ReadOnly(true))                                                  return(false);
   if(!Add(m_field_red))                                                            return(false);
//--- success
   return(true);
  }
//+------------------------------------------------------------------+
//| Creating the display element "Green" with explanatory caption    |
//+------------------------------------------------------------------+
bool CPanelDialog::CreateGreen(void)
  {
//--- coordinates
   int x1=INDENT_LEFT;
   int y1=INDENT_TOP+(EDIT_HEIGHT+CONTROLS_GAP_Y);
   int x2=x1+EDIT_WIDTH;
   int y2=y1+EDIT_HEIGHT;
//--- creating the caption
   if(!m_label_green.Create(m_chart_id,m_name+"LabelGreen",m_subwin,x1,y1+1,x2,y2)) return(false);
   if(!m_label_green.Text("Green"))                                                 return(false);
   if(!Add(m_label_green))                                                          return(false);
//--- adjusting the coordinates
   x1+=LABEL_WIDTH+CONTROLS_GAP_X;
   x2=x1+EDIT_WIDTH;
//--- creating the display element
   if(!m_field_green.Create(m_chart_id,m_name+"Green",m_subwin,x1,y1,x2,y2))        return(false);
   if(!m_field_green.Text(IntegerToString(m_green)))                                return(false);
   if(!m_field_green.ReadOnly(true))                                                return(false);
   if(!Add(m_field_green))                                                          return(false);
//--- success
   return(true);
  }
//+------------------------------------------------------------------+
//| Creating the control "Blue" with explanatory caption             |
//+------------------------------------------------------------------+
bool CPanelDialog::CreateBlue(void)
  {
//--- coordinates
   int x1=INDENT_LEFT;
   int y1=INDENT_TOP+2*(EDIT_HEIGHT+CONTROLS_GAP_Y);
   int x2=x1+EDIT_WIDTH;
   int y2=y1+EDIT_HEIGHT;
//--- creating the caption
   if(!m_label_blue.Create(m_chart_id,m_name+"LabelBlue",m_subwin,x1,y1+1,x2,y2))   return(false);
   if(!m_label_blue.Text("Blue"))                                                   return(false);
   if(!Add(m_label_blue))                                                           return(false);
//--- adjusting the coordinates
   x1+=LABEL_WIDTH+CONTROLS_GAP_X;
   x2=x1+EDIT_WIDTH;
//--- creating the display element
   if(!m_edit_blue.Create(m_chart_id,m_name+"Blue",m_subwin,x1,y1,x2,y2))           return(false);
   if(!Add(m_edit_blue))                                                            return(false);
   m_edit_blue.MinValue(BASE_COLOR_MIN);
   m_edit_blue.MaxValue(BASE_COLOR_MAX);
   m_edit_blue.Value(m_blue);
//--- success
  return(true);
  }
  
//+------------------------------------------------------------------+
//| Creating the control "ScrollV"                                   |
//+------------------------------------------------------------------+
bool CPanelDialog::CreateScrollH(void)
  {
//--- coordinates
   int x1=INDENT_LEFT;
   int y1=INDENT_TOP+2*(EDIT_HEIGHT+CONTROLS_GAP_Y);
   int x2=x1+EDIT_WIDTH;
   int y2=y1+EDIT_HEIGHT;
   
//--- creating the caption
   if(!m_scrollh.Create(m_chart_id,m_name+"ScrollV",m_subwin,x1,y1+1,x2,y2))      return(false);
   m_scrollh.Width(100);
   m_scrollh.MinPos(1);
   m_scrollh.MaxPos(20);
   if(!Add(m_scrollh))                                                           return(false);
   
//--- success
   return(true);
  }  
  
  
//+------------------------------------------------------------------+
//| Setting the "Red" value                                          |
//+------------------------------------------------------------------+
void CPanelDialog::SetRed(const int value)
  {
//--- checking
   if(value<0 || value>255) return;
//--- saving
   m_red=value;
//--- setting
   m_field_red.Text(IntegerToString(value));
//--- setting the panel color
   SetColor();
  }
//+------------------------------------------------------------------+
//| Setting the "Green" value                                        |
//+------------------------------------------------------------------+
void CPanelDialog::SetGreen(const int value)
  {
//--- checking
   if(value<0 || value>255) return;
//--- saving
   m_green=value;
//--- setting
   m_field_green.Text(IntegerToString(value));
//--- setting the panel color
   SetColor();
  }
//+------------------------------------------------------------------+
//| Setting the "Blue" value                                         |
//+------------------------------------------------------------------+
void CPanelDialog::SetBlue(const int value)
  {
//--- checking
   if(value<0 || value>255) return;
//--- saving
   m_blue=value;
//--- setting
   m_edit_blue.Value(value);
//--- setting the panel color
   SetColor();
  }
//+------------------------------------------------------------------+
//| Resize handler                                                   |
//+------------------------------------------------------------------+
bool CPanelDialog::OnResize(void)
  {
//--- calling the parent class method
   if(!CAppDialog::OnResize()) return(false);
//--- changing the color panel width
   m_color.Width(ClientAreaWidth()-(INDENT_RIGHT+LABEL_WIDTH+CONTROLS_GAP_X+EDIT_WIDTH+CONTROLS_GAP_X+INDENT_LEFT));
//--- success
   return(true);
  }
//+------------------------------------------------------------------+
//| Handler of the event of changing the "blue" level                |
//+------------------------------------------------------------------+
void CPanelDialog::OnChangeBlue(void)
  {
//--- saving
   m_blue=m_edit_blue.Value();
//--- setting the panel color
   SetColor();
  }
//+------------------------------------------------------------------+
//| Setting the panel color                                          |
//+------------------------------------------------------------------+
void CPanelDialog::SetColor(void)
  {
   m_color.ColorBackground(m_red+(m_green<<8)+(m_blue<<16));
  }
//+------------------------------------------------------------------+

 

 

 

//+------------------------------------------------------------------+
//|                                               PanelIndicator.mq5 |
//|                        Copyright 2011, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2011, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#property indicator_separate_window
#property indicator_plots               0
#property indicator_buffers             0
#property indicator_minimum             0.0
#property indicator_maximum             0.0
//+------------------------------------------------------------------+
//| Include files                                                    |
//+------------------------------------------------------------------+
#include "PanelDialog.mqh"
//+------------------------------------------------------------------+
//| Global variables                                                 |
//+------------------------------------------------------------------+
CPanelDialog ExtDialog;
//+------------------------------------------------------------------+
//| Initialization                                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creating the application dialog
   if(!ExtDialog.Create(0,"Panel Indicator",0,0,0,0,130))
      return(-1);
//--- starting the application
   if(!ExtDialog.Run())
      return(-2);
//--- creating the timer
   EventSetTimer(1);
//--- success
   return(0);
  }
//+------------------------------------------------------------------+
//| Deinitialization                                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroying the dialog
   ExtDialog.Destroy();
//--- killing the timer
   EventKillTimer();
  }
//+------------------------------------------------------------------+
//| Iteration                                                        |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
  {
//--- changing the dialog property
   ExtDialog.SetRed(MathRand()%256);
//--- returning the prev_calculated value for the next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Timer event handler                                              |
//+------------------------------------------------------------------+
void OnTimer()
  {
//--- changing the dialog property
   ExtDialog.SetGreen(MathRand()%256);
  }
//+------------------------------------------------------------------+
//| Chart event handler                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//--- handling the event
   ExtDialog.ChartEvent(id,lparam,dparam,sparam);
  }
//+------------------------------------------------------------------+
 

Also, moving the tool's window is slow and cumbersome.

Moved to the dialog window with the mouse, move the chart with. 

The problem is a bug in my opinion.  :( 

Reason: