Discussion of article "Graphical Interfaces VII: The Tabs Control (Chapter 2)" - page 3

 

How can I add CLabel to tabs, when I create CLabel item and want add to tabs compiler gives me these error:


CLabel m_overview_titlte_label;

bool CMainPanel::CreateOverviewTitleLabel(const string text)
  {

//--- Pass the panel object
   m_overview_title_label.WindowPointer(m_window);
//--- Attach to the fourth tab of the first group of tabs
   m_main_panel_tabs.AddToElementsArray(0,m_overview_title_label);  
   m_main_panel_tabs.AddToElementsArray( 
//--- Coordinates
   int x=m_window.X()+OVERVIE_TITLE_LABEL_GAP_X;
   int y=m_window.Y()+OVERVIE_TITLE_LABEL_GAP_Y;
//--- Set properties before creation
   m_overview_title_label.XSize(140);
   m_overview_title_label.YSize(18);
   //m_overview_title_label.
//--- Create control
   if(!m_overview_title_label.Create(m_chart_id,text,m_subwin,x,y))
      return(false);
//--- Add the object to the common array of object groups
   //CWndContainer::AddToElementsArray(0,m_overview_title_label);
   return(true);
  }


Compiler Error:

'WindowPointer' - function not defined MainPanel.mqh 233 27

'm_overview_title_label' - parameter conversion not allowed MainPanel.mqh 235 43

'm_overview_title_label' - variable of the same type expected MainPanel.mqh 235 43

 
Martin Fischer #:
Hi. A really nice article, but at the moment I've some questions:

1.)
I do not find an information, how I can add simple CLabel or CEdit controls to the form. (From objects.mqh)
They do not have a function like WindowPointer().
I can create these objects, but I can't attach them to the window.

The
does not work in this case...

2.)
Is the CComboBox a static object. Is it possible to modify the list of elements in the

ComboBox-Listview after the creation of the ComboBox?

Thank you!

I had same problem, I solve that by create a include file and write my label class and use that. You must create this file in Include\EasyAndFastGUI\Controls\MyLabel.mqh

That code is:

//+------------------------------------------------------------------+
//|                                                      MyLabel.mqh |
//|                                      Copyright 2023, Sassiz.Root |
//|                                         https://t.me/R00T_S4SS12 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, Sassiz.Root"
#property link      "https://t.me/R00T_S4SS12"
#property strict

#include "Element.mqh"
#include "Window.mqh"
//+------------------------------------------------------------------+
//| Class for creating a checkbox                                    |
//+------------------------------------------------------------------+
class MyLabel : public CElement
  {
private:
   //--- Pointer to the form to which the element is attached
   CWindow          *m_wnd;
   //--- Objects for creating a checkbox

   CLabel            m_label;

   //--- Text of the checkbox
   string            m_label_text;
   //--- Text label margins
   int               m_label_x_gap;
   int               m_label_y_gap;
   //--- Colors of the text label in different states
   color             m_label_color;
   color             m_label_color_off;
   color             m_label_color_hover;
   color             m_label_color_locked;
   color             m_label_color_array[];
   //--- Priorities of the left mouse button press
   int               m_zorder;
   int               m_area_zorder;

   //---
public:
                     MyLabel(void);
                    ~MyLabel(void);
   //--- Methods for creating a checkbox
   bool              CreateLabel(const long chart_id,const int subwin,const string text,const int x,const int y);
   //---
private:
   bool              CreateLabel2(void);
   //---
public:
   //--- (1) Stores the form pointer, (2) return/set the state of the checkbox
   void              WindowPointer(CWindow &object)                 { m_wnd=::GetPointer(object);            }

   //--- (1) Background color, (2) margins for the text label

   void              LabelXGap(const int x_gap)                     { m_label_x_gap=x_gap;                   }
   void              LabelYGap(const int y_gap)                     { m_label_y_gap=y_gap;                   }
   //--- Color of the text in different states
   void              LabelColor(const color clr)                    { m_label_color=clr;                     }

   //--- (1) Description of the checkbox, (2) return/set the state of the checkbox button
   string            LabelText(void)                          const { return(m_label.Description());         }

   //--- Changing the color
   void              ChangeObjectsColor(void);
   //---
public:
   //--- Chart event handler
   virtual void      OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam);
   //--- Timer
   virtual void      OnEventTimer(void);
   //--- Moving the element
   virtual void      Moving(const int x,const int y);
   //--- (1) Show, (2) hide, (3) reset, (4) delete
   virtual void      Show(void);
   virtual void      Hide(void);
   virtual void      Reset(void);
   virtual void      Delete(void);
   //--- (1) Set, (2) reset priorities of the left mouse button press
   virtual void      SetZorders(void);
   virtual void      ResetZorders(void);
   //--- Reset the color
   virtual void      ResetColors(void);
   virtual void      SetText(string text);
   virtual void      SetFontSize(int fontSize);
   //---
private:
   //--- Handling of the press on the element
   bool              OnClickLabel(const string clicked_object);
  };
//+------------------------------------------------------------------+
//| Constructor                                                      |
//+------------------------------------------------------------------+
MyLabel::MyLabel(void) :      
                             m_label_x_gap(20),
                             m_label_y_gap(2),
                             m_label_color(clrBlack)
                             
  {
//--- Store the name of the element class in the base class
   CElement::ClassName(CLASS_NAME);
//--- Set priorities of the left mouse button click
   m_zorder      =0;
   m_area_zorder =1;
  }
//+------------------------------------------------------------------+
//| Destructor                                                       |
//+------------------------------------------------------------------+
MyLabel::~MyLabel(void)
  {
  }
//+------------------------------------------------------------------+
//| Event handling                                                |
//+------------------------------------------------------------------+
void MyLabel::OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam)
  {
//--- Handling of the cursor movement event
   if(id==CHARTEVENT_MOUSE_MOVE)
     {
      //--- Leave, if the element is hidden
      if(!CElement::IsVisible())
         return;
      //--- Leave, if numbers of subwindows do not match
      if(CElement::m_subwin!=CElement::m_mouse.SubWindowNumber())
         return;
      //--- Checking the focus over element
      CElement::MouseFocus(m_mouse.X()>X() && m_mouse.X()<X2() && m_mouse.Y()>Y() && m_mouse.Y()<Y2());
      return;
     }
//--- Handling the left mouse button click on the object
   if(id==CHARTEVENT_OBJECT_CLICK)
     {
      //--- Pressing on the checkbox
      if(OnClickLabel(sparam))
         return;
     }
  }
//+------------------------------------------------------------------+
//| Timer                                                            |
//+------------------------------------------------------------------+
void MyLabel::OnEventTimer(void)
  {
//--- If the form is not blocked
   if(!m_wnd.IsLocked())
      //--- Changing the color of the element objects
      ChangeObjectsColor();
  }
//+------------------------------------------------------------------+
//| Creates a group of the checkbox objects                          |
//+------------------------------------------------------------------+
bool MyLabel::CreateLabel(const long chart_id,const int subwin,const string text,const int x,const int y)
  {
//--- Leave, if there is no form pointer
   if(!CElement::CheckWindowPointer(::CheckPointer(m_wnd)))
      return(false);
//--- Initializing variables
   m_id         =m_wnd.LastId()+1;
   m_chart_id   =chart_id;
   m_subwin     =subwin;
   m_x          =x;
   m_y          =y;
   m_label_text =text;
//--- Margins from the edge
   CElement::XGap(CElement::X()-m_wnd.X());
   CElement::YGap(CElement::Y()-m_wnd.Y());
//--- Creating an element

   if(!CreateLabel2())
      return(false);
//--- Hide the element if the window is a dialog one or is minimized
   if(m_wnd.WindowType()==W_DIALOG || m_wnd.IsMinimized())
      Hide();
//---
   return(true);
  }


//+------------------------------------------------------------------+
//| Creates checkbox label                                           |
//+------------------------------------------------------------------+
bool MyLabel::CreateLabel2(void)
  {
//--- Forming the object name
   string name=CElement::ProgramName()+"_lable_"+(string)CElement::Id();
//--- Coordinates
   int x =CElement::X()+m_label_x_gap;
   int y =CElement::Y()+m_label_y_gap;
//--- Text color according to the state
   color label_color=clrBlack;//(m_check_button_state) ? m_label_color : m_label_color_off;
//--- Set the object
   if(!m_label.Create(m_chart_id,name,m_subwin,x,y))
      return(false);
//--- set properties
   m_label.Description(m_label_text);
   m_label.Font(FONT);
   m_label.FontSize(FONT_SIZE);
   m_label.Color(label_color);
   m_label.Corner(m_corner);
   m_label.Anchor(m_anchor);
   m_label.Selectable(false);
   m_label.Z_Order(m_zorder);
   m_label.Tooltip("\n");
//--- Margins from the edge
   m_label.XGap(x-m_wnd.X());
   m_label.YGap(y-m_wnd.Y());
//--- Initializing gradient array
   CElement::InitColorArray(label_color,m_label_color_hover,m_label_color_array);
//--- Store the object pointer
   CElement::AddToArray(m_label);
   return(true);
  }
//+------------------------------------------------------------------+
//| Moving elements                                                  |
//+------------------------------------------------------------------+
void MyLabel::Moving(const int x,const int y)
  {
//--- Leave, if the element is hidden
   if(!CElement::IsVisible())
      return;
//--- Storing indents in the element fields
   CElement::X(x+XGap());
   CElement::Y(y+YGap());
//--- Storing coordinates in the fields of the objects
   m_label.X(x+m_label.XGap());
   m_label.Y(y+m_label.YGap());
//--- Updating coordinates of graphical objects
   m_label.X_Distance(m_label.X());
   m_label.Y_Distance(m_label.Y());
  }
//+------------------------------------------------------------------+
//| Changing the object color when the cursor is hovering over it    |
//+------------------------------------------------------------------+
void MyLabel::ChangeObjectsColor(void)
  {
//--- Leave, if the element is blocked

//---
   color label_color=clrBlack;//(m_check_button_state) ? m_label_color : m_label_color_off;
   CElement::ChangeObjectColor(m_label.Name(),CElement::MouseFocus(),OBJPROP_COLOR,label_color,m_label_color_hover,m_label_color_array);
  }
//+------------------------------------------------------------------+
//| Shows combobox                                                   |
//+------------------------------------------------------------------+
void MyLabel::Show(void)
  {
//--- Leave, if the element is already visible
   if(CElement::IsVisible())
      return;
//--- Make all objects visible
   for(int i=0; i<CElement::ObjectsElementTotal(); i++)
      CElement::Object(i).Timeframes(OBJ_ALL_PERIODS);
//--- State of visibility
   CElement::IsVisible(true);
  }
//+------------------------------------------------------------------+
//| Hides combobox                                                   |
//+------------------------------------------------------------------+
void MyLabel::Hide(void)
  {
//--- Leave, if the element is already visible
   if(!CElement::IsVisible())
      return;
//--- Hide all objects
   for(int i=0; i<CElement::ObjectsElementTotal(); i++)
      CElement::Object(i).Timeframes(OBJ_NO_PERIODS);
//--- State of visibility
   CElement::IsVisible(false);
  }
//+------------------------------------------------------------------+
//| Redrawing                                                        |
//+------------------------------------------------------------------+
void MyLabel::Reset(void)
  {
//--- Leave, if this is a drop-down element
   if(CElement::IsDropdown())
      return;
//--- Hide and show
   Hide();
   Show();
  }
//+------------------------------------------------------------------+
//| Deletion                                                         |
//+------------------------------------------------------------------+
void MyLabel::Delete(void)
  {
//--- Removing objects
   m_label.Delete();
//--- Emptying the array of the objects
   CElement::FreeObjectsArray();
//--- Initializing of variables by default values
   CElement::MouseFocus(false);
   CElement::IsVisible(true);
  }
//+------------------------------------------------------------------+
//| Seth the priorities                                              |
//+------------------------------------------------------------------+
void MyLabel::SetZorders(void)
  {
   m_label.Z_Order(m_zorder);
  }
//+------------------------------------------------------------------+
//| Reset the priorities                                             |
//+------------------------------------------------------------------+
void MyLabel::ResetZorders(void)
  {
   m_label.Z_Order(0);
  }
//+------------------------------------------------------------------+
//| Reset the color of the element objects                           |
//+------------------------------------------------------------------+
void MyLabel::ResetColors(void)
  {

//--- Reset the color
   m_label.Color(clrBlack);
//--- Zero the focus
   CElement::MouseFocus(false);
  }

//+------------------------------------------------------------------+
//| Clicking on the element header                                   |
//+------------------------------------------------------------------+
bool MyLabel::OnClickLabel(const string clicked_object)
  {

//--- The mouse cursor is currently over the element
   m_label.Color(m_label_color_hover);
//--- Send a message about it
   ::EventChartCustom(m_chart_id,ON_CLICK_LABEL,CElement::Id(),0,m_label.Description());
   return(true);
  }
//+------------------------------------------------------------------+


void MyLabel::SetText(string text){
   m_label.Description(text);
}

void MyLabel::SetFontSize(int fontSize){
   m_label.FontSize(fontSize);
}

Then create object from MyLabel Class like this and use it:

   //---Label
   MyLabel           m_overview_title_label;

Then:

//+------------------------------------------------------------------+
//| Creates OverviewTitleLabel                                       |
//+------------------------------------------------------------------+
bool CMainPanel::CreateOverviewTitleLabel(const string text)
  {

//--- Pass the panel object
   m_overview_title_label.WindowPointer(m_window);
//--- Attach to the fourth tab of the first group of tabs
   m_main_panel_tabs.AddToElementsArray(0,m_overview_title_label);  
//--- Coordinates
   int x=m_window.X()+OVERVIE_TITLE_LABEL_GAP_X;
   int y=m_window.Y()+OVERVIE_TITLE_LABEL_GAP_Y;
//--- Set properties before creation
   m_overview_title_label.XSize(140);
   m_overview_title_label.YSize(18);
   m_overview_title_label.SetText(text);
   m_overview_title_label.SetFontSize(18);
   //m_overview_title_label.
//--- Create control
   if(!m_overview_title_label.CreateLabel(m_chart_id,m_subwin,text,x,y))
      return(false);
//--- Add the object to the common array of object groups
   CWndContainer::AddToElementsArray(0,m_overview_title_label);
   return(true);
  }
 
If we increase the number of tabs, whether vertically or horizontally, there will be no scrolling capability, causing the window to extend beyond its limits and reducing its efficiency.