How to change the minimum CAppDialog panel size of the panel when minimized?

David Anthony Gonsalves  

Below in the coded section, I have a CGraphicalPanel class representing my Panel.


But I see when minimized the panel in X dimension, bit too narrow.

How would I change the the size of the panel when minimized?

Would like the panel to be large in X dimension when minimized.

All I know that CAppDialog >> CDialog has a `m_min_rect` variable, I presume this has to do with the size when minimized, but it would like to change this during the initialization of my panel called CGraphicalPanel.



//+------------------------------------------------------------------+
//|                                             MT5_GB_GUI_Panel.mqh |
//|                                  Copyright 2022, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Ltd."
#property link "https://www.mql5.com"
//+------------------------------------------------------------------+
//| Include 1                                                        |
//+------------------------------------------------------------------+
#include <Controls\Defines.mqh>

//+------------------------------------------------------------------+
//| Define statements to change default dialog settings              |
//+------------------------------------------------------------------+
#undef CONTROLS_FONT_NAME
#undef CONTROLS_DIALOG_COLOR_CLIENT_BG
#define CONTROLS_FONT_NAME "Consolas"
#define CONTROLS_DIALOG_COLOR_CLIENT_BG C'0x20,0x20,0x20' // hex color

//+------------------------------------------------------------------+
//| Include 2                                                        |
//+------------------------------------------------------------------+
#include <Controls\Button.mqh>
#include <Controls\Dialog.mqh>
#include <Controls\Label.mqh>

//+------------------------------------------------------------------+
//| Inputs                                                           |
//+------------------------------------------------------------------+
input string group = "==== Panel Inputs ====";
static input int InpPanelWidth = 450;           // width of panel
static input int InpPanelHeight = 350;          // height of panel
static input int InpPanelFontSize = 16;         // font size
static input color InpPanelTxtColor = clrWhite; // text color

//+------------------------------------------------------------------+
//| CGraphicalPanel                                                  |
//+------------------------------------------------------------------+
class CGraphicalPanel : public CAppDialog
        {
private:
        // Declare private variables
        bool m_f_color;

        // Declare buttons
        CButton m_bChangeColor;

        // Declare labels
        CLabel m_l_NumberOfActiveTrades;

        // Declare private methods
        void OnClickChangeColor();
        bool CheckInputs();
        bool CreatePanel();
        template <typename T>
        void CreateElement(T &label, string name, int x1, int y1, int x2, int y2, string text, color clr, int fontSize);

public:
        // Declare Public Methods
        void CGraphicalPanel();
        void ~CGraphicalPanel();

        bool OnInit();
        void Update();

        // chart event handler
        void PanelChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam);
        };
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
// Constructor
void CGraphicalPanel::CGraphicalPanel() {

}
// Destructor
void CGraphicalPanel::~CGraphicalPanel() {}
// For creating labels, buttons, etc.
template <typename T>
void CGraphicalPanel::CreateElement(T &element, string name, int x1, int y1, int x2, int y2, string text, color clr, int fontSize)
        {
        element.Create(
                NULL, // chart id
                name, // name
                0,    // chart subwindow, 0 = main window
                x1,   // X coordinate of the upper left corner
                y1,   // Y coordinate of the upper left corner
                x2,   // X coordinate of the lower right corner
                y2    // Y coordinate of the lower right corner
        );
        element.Text(text);
        element.Color(clr);
        element.FontSize(fontSize);
        this.Add(element); // add label to panel
        }
//
bool CGraphicalPanel::OnInit()
        {
        // check inputs
        if (!CheckInputs())
                {
                return false;
                }
        // create panel
        if (!this.CreatePanel())
                {
                return false;
                }

        return true;
        }
//+------------------------------------------------------------------+
bool CGraphicalPanel::CheckInputs(void)
        {
        if (InpPanelWidth <= 0)
                {
                Print("Panel width <= 0");
                return false;
                }
        if (InpPanelHeight <= 0)
                {
                Print("Panel height <= 0");
                return false;
                }
        if (InpPanelFontSize <= 0)
                {
                Print("Panel font size <= 0");
                return false;
                }

        return true;
        }
// Update Panel Elements
void CGraphicalPanel::Update(void)
        {
        m_l_NumberOfActiveTrades.Text("Number of active trades: " + (string)SymbolInfoDouble(Symbol(), SYMBOL_ASK));
        }
// Create Panel
bool CGraphicalPanel::CreatePanel(void)
        {
        /// Create Dialog Panel
        this.Create(NULL, "Panel Test", 0, 0, 0, InpPanelWidth, InpPanelHeight);

        /// Create Dialog Panel Labels
        // Input Label
        CreateElement(m_l_NumberOfActiveTrades, "l_NumberOfActiveTrades", 10, 10, 1, 1, "Number of active trades: " + (string)SymbolInfoDouble(Symbol(), SYMBOL_ASK), clrLime, InpPanelFontSize);

        /// Create Dialog Panel Buttons
        // Change Color Button
        CreateElement(m_bChangeColor, "bChangeColor", 10, 250, 100, 180, "Change Color", clrWhite, InpPanelFontSize);
        m_bChangeColor.ColorBackground(clrDarkRed);


        // run panel
        if (!Run())
                {
                Print("Failed to run panel");
                return false;
                }

        // refresh chart
        ChartRedraw();

        return true;
        }
//
void CGraphicalPanel::PanelChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam)
        {
        // call chart event method of base class
        ChartEvent(id, lparam, dparam, sparam);

        // check if button was clicked
        if (id == CHARTEVENT_OBJECT_CLICK && sparam == "bChangeColor")
                {
                OnClickChangeColor();
                }
        }
//+------------------------------------------------------------------+
void CGraphicalPanel::OnClickChangeColor(void)
        {
        Print("Button Clicked");
        ChartSetInteger(NULL, CHART_COLOR_BACKGROUND, m_f_color ? clrWhite : clrAqua);
        m_f_color = !m_f_color;
        ChartRedraw();
        }
//+------------------------------------------------------------------+
Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • 2023.01.12
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
David Anthony Gonsalves  
David Anthony Gonsalves:

Below in the coded section, I have a CGraphicalPanel class representing my Panel.


But I see when minimized the panel in X dimension, bit too narrow.

How would I change the the size of the panel when minimized?

Would like the panel to be large in X dimension when minimized.

All I know that CAppDialog >> CDialog has a `m_min_rect` variable, I presume this has to do with the size when minimized, but it would like to change this during the initialization of my panel called CGraphicalPanel.



Well, figured it out, by redefining:

CONTROLS_DIALOG_MINIMIZE_WIDTH
//+------------------------------------------------------------------+
//| Include 1                                                        |
//+------------------------------------------------------------------+
#include "MT5_GB-Logger_static.mqh"
#include <Controls\Defines.mqh> // IMPORT THEN REDEFINE BEFORE OTHER CONTROL IMPORTS

//+------------------------------------------------------------------+
//| Define statements to change default dialog settings              |
//+------------------------------------------------------------------+
// Undefine before re-defining
#undef CONTROLS_FONT_NAME
#undef CONTROLS_DIALOG_COLOR_CLIENT_BG
#undef CONTROLS_DIALOG_MINIMIZE_WIDTH
// Re-defining
#define CONTROLS_FONT_NAME "Consolas"
#define CONTROLS_DIALOG_COLOR_CLIENT_BG C'0x20,0x20,0x20'
#define CONTROLS_DIALOG_MINIMIZE_WIDTH 200 // THIS CHANGES MINIMIZED PANEL WIDTH
David Anthony Gonsalves  
Tobias Johannes Zimmer #:
In MQL5 Standard Library in documentation there is a method Minimized() from CAppDialog (which you are using), you can set it to true or false.
That is Method is called by clicking the minimize button on the panel. What I wanted to do was alter the width of panel in the minimized state, I figured it out eventually be redefining "CONTROLS_DIALOG_MINIMIZE_WIDTH" before importing the controls libraries. (In my first reply above)