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(conststring text)
{
//--- Pass the panel objectm_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(
//--- Coordinatesint 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 controlif(!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 definedMainPanel.mqh23327
'm_overview_title_label' - parameter conversion not allowedMainPanel.mqh23543
'm_overview_title_label' - variable of the same type expectedMainPanel.mqh23543
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 checkboxstring m_label_text;
//--- Text label marginsint m_label_x_gap;
int m_label_y_gap;
//--- Colors of the text label in different statescolor 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 pressint m_zorder;
int m_area_zorder;
//---public:
MyLabel(void);
~MyLabel(void);
//--- Methods for creating a checkboxbool CreateLabel(constlong chart_id,constint subwin,conststring text,constint x,constint y);
//---private:
bool CreateLabel2(void);
//---public:
//--- (1) Stores the form pointer, (2) return/set the state of the checkboxvoid WindowPointer(CWindow &object) { m_wnd=::GetPointer(object); }
//--- (1) Background color, (2) margins for the text labelvoid LabelXGap(constint x_gap) { m_label_x_gap=x_gap; }
void LabelYGap(constint y_gap) { m_label_y_gap=y_gap; }
//--- Color of the text in different statesvoid LabelColor(constcolor clr) { m_label_color=clr; }
//--- (1) Description of the checkbox, (2) return/set the state of the checkbox buttonstring LabelText(void) const { return(m_label.Description()); }
//--- Changing the colorvoid ChangeObjectsColor(void);
//---public:
//--- Chart event handlervirtualvoid OnEvent(constint id,constlong &lparam,constdouble &dparam,conststring &sparam);
//--- Timervirtualvoid OnEventTimer(void);
//--- Moving the elementvirtualvoid Moving(constint x,constint y);
//--- (1) Show, (2) hide, (3) reset, (4) deletevirtualvoid Show(void);
virtualvoid Hide(void);
virtualvoid Reset(void);
virtualvoid Delete(void);
//--- (1) Set, (2) reset priorities of the left mouse button pressvirtualvoid SetZorders(void);
virtualvoid ResetZorders(void);
//--- Reset the colorvirtualvoid ResetColors(void);
virtualvoid SetText(string text);
virtualvoid SetFontSize(int fontSize);
//---private:
//--- Handling of the press on the elementbool OnClickLabel(conststring 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(constint id,constlong &lparam,constdouble &dparam,conststring &sparam)
{
//--- Handling of the cursor movement eventif(id==CHARTEVENT_MOUSE_MOVE)
{
//--- Leave, if the element is hiddenif(!CElement::IsVisible())
return;
//--- Leave, if numbers of subwindows do not matchif(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 objectif(id==CHARTEVENT_OBJECT_CLICK)
{
//--- Pressing on the checkboxif(OnClickLabel(sparam))
return;
}
}
//+------------------------------------------------------------------+//| Timer |//+------------------------------------------------------------------+void MyLabel::OnEventTimer(void)
{
//--- If the form is not blockedif(!m_wnd.IsLocked())
//--- Changing the color of the element objects
ChangeObjectsColor();
}
//+------------------------------------------------------------------+//| Creates a group of the checkbox objects |//+------------------------------------------------------------------+bool MyLabel::CreateLabel(constlong chart_id,constint subwin,conststring text,constint x,constint y)
{
//--- Leave, if there is no form pointerif(!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 elementif(!CreateLabel2())
return(false);
//--- Hide the element if the window is a dialog one or is minimizedif(m_wnd.WindowType()==W_DIALOG || m_wnd.IsMinimized())
Hide();
//---return(true);
}
//+------------------------------------------------------------------+//| Creates checkbox label |//+------------------------------------------------------------------+bool MyLabel::CreateLabel2(void)
{
//--- Forming the object namestring name=CElement::ProgramName()+"_lable_"+(string)CElement::Id();
//--- Coordinatesint x =CElement::X()+m_label_x_gap;
int y =CElement::Y()+m_label_y_gap;
//--- Text color according to the statecolor label_color=clrBlack;//(m_check_button_state) ? m_label_color : m_label_color_off;//--- Set the objectif(!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(constint x,constint y)
{
//--- Leave, if the element is hiddenif(!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 visibleif(CElement::IsVisible())
return;
//--- Make all objects visiblefor(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 visibleif(!CElement::IsVisible())
return;
//--- Hide all objectsfor(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 elementif(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(conststring 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(conststring 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);
//--- Coordinatesint 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 controlif(!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.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
How can I add CLabel to tabs, when I create CLabel item and want add to tabs compiler gives me these error:
Compiler Error:
'WindowPointer' - function not defined MainPanel.mqh 233 27
'm_overview_title_label' - parameter conversion not allowed MainPanel.mqh 235 43
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:
Then create object from MyLabel Class like this and use it:
//---Label MyLabel m_overview_title_label;Then: