Discussion of article "How to create a graphical panel of any complexity level" - page 7

 
Like
 

Hi thanks for your amazing tutorial 

I'm trying to make my own , in my panel by click on one button the other one should be disable and hide , it will be hide when i click in the area of hidden button it still work 

I put my codes here if you could help me that will be great

Indicator:

//+------------------------------------------------------------------+
//|                                             Indicator_Q_Test.mq4 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#include  <WinUser32.mqh>
#include "PanelDialog_Q.mqh"
CPanelDialogQ ExtDialog;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping

   if(!ExtDialog.CreateQ(0,"Question",0,100,100,400,230,"This the test Question?"))
      return(INIT_FAILED);
//--- run application
   if(!ExtDialog.Run())
      return(INIT_FAILED);
 
      

//---
   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)
  {
//---
      ExtDialog.ChartEvent(id,lparam,dparam,sparam);

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

   ExtDialog.Destroy(reason);


  }

Class:

//+------------------------------------------------------------------+
//|                                                  PanelDialog.mqh |
//|                   Copyright 2009-2015, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#include <Controls\Dialog.mqh>
#include <Controls\Button.mqh>
#include <Controls\Edit.mqh>
#include <Controls\ListView.mqh>
#include <Controls\ComboBox.mqh>
#include <Controls\SpinEdit.mqh>
#include <Controls\RadioGroup.mqh>
#include <Controls\CheckGroup.mqh>
#include <Controls\Label.mqh>
#include <Controls\Scrolls.mqh>
//+------------------------------------------------------------------+
//| defines                                                          |
//+------------------------------------------------------------------+
//--- indents and gaps
#define INDENT_LEFT_ScrollQ                         (11)      // indent from left (with allowance for border width)(for Scroll Bar Only)
#define INDENT_LEFTQ                         (11)      // indent from left (with allowance for border width)
#define INDENT_TOPQ                          (11)      // indent from top (with allowance for border width)
#define INDENT_RIGHTQ                        (11)      // indent from right (with allowance for border width)
#define INDENT_BOTTOMQ                       (11)      // indent from bottom (with allowance for border width)
#define CONTROLS_GAP_XQ                      (80)      // gap by X coordinate
#define CONTROLS_GAP_YQ                      (40)      // gap by Y coordinate
//--- for buttons
#define BUTTON_WIDTHQ                        (60)     // size by X coordinate
#define BUTTON_HEIGHTQ                       (20)      // size by Y coordinate
//--- for the indication area

#define EDIT_HEIGHTQ                         (20)      // size by Y coordinate
#define GROUP_WIDTHQ                         (150)     // size by X coordinate
#define LIST_HEIGHTQ                         (379)     // size by Y coordinate
#define RADIO_HEIGHTQ                        (56)      // size by Y coordinate
#define CHECK_HEIGHTQ                        (93)      // size by Y coordinate
//+------------------------------------------------------------------+
//| Class CPanelDialog                                               |
//| Usage: main dialog of the SimplePanel application                |
//+------------------------------------------------------------------+
class CPanelDialogQ : public CAppDialog
  {
private:

   CLabel            m_Label_Q_text;


   CButton           m_button_Yes;
   CButton           m_button_No;




   //****************************************************


public:
                     CPanelDialogQ(void);
                    ~CPanelDialogQ(void);
   //--- create
   virtual bool      CreateQ(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2,string QText);
   //--- chart event handler
   virtual bool      OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam);

protected:

   //--- create dependent controls

   bool              CreateLabel_Q_text(string QT);

   bool              CreateButton_Yes(void);
   bool              CreateButton_No(void);


   void              OnClick_button_Yes(void);
   void              OnClick_button_No(void);


  };
//+------------------------------------------------------------------+
//| Event Handling                                                   |
//+------------------------------------------------------------------+
EVENT_MAP_BEGIN(CPanelDialogQ)

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
ON_EVENT(ON_CLICK,m_button_Yes,OnClick_button_Yes)
ON_EVENT(ON_CLICK,m_button_No,OnClick_button_No)

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
EVENT_MAP_END(CAppDialog)
//+------------------------------------------------------------------+
//| Constructor                                                      |
//+------------------------------------------------------------------+
CPanelDialogQ::CPanelDialogQ(void)
  {
  }
//+------------------------------------------------------------------+
//| Destructor                                                       |
//+------------------------------------------------------------------+
CPanelDialogQ::~CPanelDialogQ(void)
  {
  }
//+------------------------------------------------------------------+
//| Create                                                           |
//+------------------------------------------------------------------+
bool CPanelDialogQ::CreateQ(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2,string QText)
  {
   if(!CAppDialog::Create(chart,name,subwin,x1,y1,x2,y2))
      return(false);
//--- create dependent controls

   if(!CreateLabel_Q_text(QText))
      return(false);
   if(!CreateButton_Yes())
      return(false);
   if(!CreateButton_No())
      return(false);

//--- succeed
   return(true);
  }


//+------------------------------------------------------------------+

//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
bool CPanelDialogQ::CreateLabel_Q_text(string QT)
  {
//--- coordinates
   int x1=INDENT_LEFTQ;
   int y1=INDENT_TOPQ;
   int x2=ClientAreaWidth()-(INDENT_RIGHTQ+BUTTON_WIDTHQ+CONTROLS_GAP_XQ);
   int y2=y1+EDIT_HEIGHTQ;

//--- create
   if(!m_Label_Q_text.Create(m_chart_id,"QT",m_subwin,x1,y1,x2,y2))
      return(false);
   if(!m_Label_Q_text.Text(QT))
      return(false);
   if(!m_Label_Q_text.FontSize(12))
      return(false);
   if(!m_Label_Q_text.Color(clrBlack))
      return(false);
   if(!m_Label_Q_text.ColorBorder(clrBlack))
      return(false);
   if(!m_Label_Q_text.ColorBackground(clrBlack))
      return(false);
// if(!m_edit.ReadOnly(true))
//    return(false);
   if(!Add(m_Label_Q_text))
      return(false);

   m_Label_Q_text.Alignment(WND_ALIGN_WIDTH,INDENT_LEFTQ,0,INDENT_RIGHTQ+BUTTON_WIDTHQ+CONTROLS_GAP_XQ,0);
//--- succeed
   return(true);
  }
//+------------------------------------------------------------------+


//+------------------------------------------------------------------+
bool CPanelDialogQ::CreateButton_Yes(void)
  {
//--- coordinates
   int x1=INDENT_LEFTQ;
   int y1=INDENT_TOPQ+CONTROLS_GAP_YQ;
   int x2=x1+BUTTON_WIDTHQ;
   int y2=y1+BUTTON_HEIGHTQ;
//--- create
   if(!m_button_Yes.Create(m_chart_id,m_name+"Yes",m_subwin,x1,y1,x2,y2))
      return(false);
   if(!m_button_Yes.Text("Yes"))
      return(false);
   if(!Add(m_button_Yes))
      return(false);
   m_button_Yes.Alignment(WND_ALIGN_RIGHT,0,0,INDENT_RIGHTQ+CONTROLS_GAP_XQ*2,0);
//--- succeed
   return(true);
  }





//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
bool CPanelDialogQ::CreateButton_No(void)
  {
//--- coordinates
   int x1=INDENT_LEFTQ+CONTROLS_GAP_XQ;
   int y1=INDENT_TOPQ+CONTROLS_GAP_YQ;
   int x2=x1+BUTTON_WIDTHQ;
   int y2=y1+BUTTON_HEIGHTQ;
//--- create
   if(!m_button_No.Create(m_chart_id,m_name+"NO",m_subwin,x1,y1,x2,y2))
      return(false);
   if(!m_button_No.Text("NO"))
      return(false);
   if(!Add(m_button_No))
      return(false);
   m_button_No.Alignment(WND_ALIGN_RIGHT,0,0,INDENT_RIGHTQ+CONTROLS_GAP_XQ*1,0);
//--- succeed
   return(true);
  }

//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
void CPanelDialogQ::OnClick_button_Yes(void)
  {

   Print("OnClick_button_Yes", "Last Error: ",GetLastError());

  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
void CPanelDialogQ::OnClick_button_No(void)
  {

   Print("OnClick_button_No", "Last Error: ",GetLastError());

m_button_Yes.Hide();
m_button_Yes.Disable();
m_button_Yes.Deactivate();

  }
//+------------------------------------------------------------------+
 

Hello, I managed to make my panel successfully. Thank you very much for your amazing tutorial.

 

Hello Vladimir,
first i also like to thank you for your great tutorial. I found a problem in using it in a template: Just put any of your applications into a template of an empty chart. After loading this template the application will come up twice like shown in the picture. Do you have any idea how to fix this?

Thank you in advance

Files:
 

Why is the panel/window cannot be dragged/moved past the chart boundaries? 

What is the difference with Anatoli's easyfastgui library?

 
Seyedmasoud Hashemi #:

Hi thanks for your amazing tutorial 

I'm trying to make my own , in my panel by click on one button the other one should be disable and hide , it will be hide when i click in the area of hidden button it still work 

I put my codes here if you could help me that will be great

Indicator:

Class:

Hey, I only want to ask if you had solved this problem. I tried it a long time to make a panel with hidden objects, but when I minimized the panel an restore it all the hidden objects are visible an active.