Hi,
I am having hard time creating a panel with the control libraries on mt4, this is the first time i am using them.
I created a rectangle lbl as background and a normal combo box to switch between buy and sell orders, i have tried a lot of ways to pull this off, but seems to have a problem.
The List is filled with the values I wanted, the button reacts when i click, but only the bitmap changes, the list is not opened or closed. I printed out everything i can think of, both in the EA and libraries, but seems to be ok(apparently its not ok).
This is the code i am using to create the box and fill values, in the beginning i have included the files.
I belive there may be more to this except the methods i am using but lets see.
Id be grateful if somebody helps with this !
Thanks in advance
There is not enough information from your code. I suppose you use the Add method for your panel class (Add(cmbox)). Maybe you have forgot call the Run method (panel class).
void place_gui() //Placing the initial "skeletton" of the GUI in OnInit() { int x=0,y=0; int indentx = 0; int indenty = 15; int verticalSpace=5; int rect_sizex=300,rect_sizey=300; rect(indentx,indenty,rect_sizex,rect_sizey,"Rect "+IntegerToString(rect_id),clrGray,clrWhiteSmoke,1); x+=indentx+10; y+=indenty+10; label(x,y,"Select Order Type :",clrWhiteSmoke,"label ",8); x+=130; cmbox.ListViewItems(2); if(!cmbox.Create(0,"type1",0,x,y,x+150,y+20)) {Print("Error creating a combobox ! ",GetLastError());} if(!cmbox.ItemAdd("Sell")) {Print("Error in adding item ",GetLastError());} if(!cmbox.ItemAdd("Buy")) {Print("Error in adding item ",GetLastError());} }
this i place into oninit
#include <Controls\\CheckBox.mqh> #include <Controls\\ComboBox.mqh> #include <Controls\\ListView.mqh> CCheckBox check_box; CComboBox cmbox; CListView mls;
and that is the beginning of the code
Thats pretty much it !
I am trying to simplify it as i dont know the library that much, yet
You have to start with CAppDialog (#include <Controls\Dialog.mqh>) and then create some items (e.g. your combo box). The items must be added to CAppDialog and must be called CAppDialog.Run(). Below is an example.
#property strict //+------------------------------------------------------------------+ //| Includes | //+------------------------------------------------------------------+ #include <Controls\Dialog.mqh> #include <Controls\Label.mqh> #include <Controls\Panel.mqh> #include <Controls\ComboBox.mqh> //+------------------------------------------------------------------+ //| Global parameters | //+------------------------------------------------------------------+ int panelXX = 20; int panelYY = 20; int panelWidth = 300; int panelHeight = 300; //+------------------------------------------------------------------+ //| Global variabels | //+------------------------------------------------------------------+ //--- Panel itself CAppDialog* m_panel; //--- Bid objects CPanel m_bidcolor; CLabel m_bidlabel; //--- Ask objects CPanel m_askcolor; CLabel m_asklabel; //--- ComboBox CComboBox m_cmbox; //+------------------------------------------------------------------+ //| On Init | //+------------------------------------------------------------------+ int OnInit() { m_panel=new CAppDialog(); //--- Panel create m_panel.Create(0,"TEST PANEL",0,panelXX,panelYY,panelWidth,panelHeight); //--- Bid label and colors m_bidcolor.Create(0,"Bid Background Color",0,1,1,panelWidth-30,30); m_bidcolor.ColorBackground(clrYellow); m_panel.Add(m_bidcolor); m_bidlabel.Create(0,"Bid Text",0,5,5,0,0); m_bidlabel.Text("Bid "+DoubleToString(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits)); m_bidlabel.Color(clrBlue); m_panel.Add(m_bidlabel); //--- Ask label and colors m_askcolor.Create(0,"Ask Background Color",0,1,101,panelWidth-30,130); m_askcolor.ColorBackground(clrAqua); m_panel.Add(m_askcolor); m_asklabel.Create(0,"Ask Text",0,5,105,0,0); m_asklabel.Text("Ask "+DoubleToString(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits)); m_asklabel.Color(clrRed); m_panel.Add(m_asklabel); //--- ComboBox m_cmbox.Create(0,"ComboBox",0,60,201,panelWidth-90,221); m_cmbox.ItemAdd("Sell"); m_cmbox.ItemAdd("Buy"); m_cmbox.Select(0); // Default value is Sell m_panel.Add(m_cmbox); //--- Run panel m_panel.Run(); return(0); } //+------------------------------------------------------------------+ //| On DeInit | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- Destroy panel m_panel.Destroy(reason); if(CheckPointer(m_panel)==POINTER_DYNAMIC) delete m_panel; //--- Delete all objects ObjectsDeleteAll(0,0); } //+------------------------------------------------------------------+ //| On Calculate | //+------------------------------------------------------------------+ void OnTick() { //--- A very simples bid label m_bidlabel.Text("Bid "+DoubleToString(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits)); //--- A very simples ask label m_asklabel.Text("Ask "+DoubleToString(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits)); } //+------------------------------------------------------------------+ //| On Chart Event | //+------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { //--- Move the panel with the mouse m_panel.ChartEvent(id,lparam,dparam,sparam); } //+------------------------------------------------------------------+
You have to start with CAppDialog (#include <Controls\Dialog.mqh>) and then create some items (e.g. your combo box). The items must be added to CAppDialog and must be called CAppDialog.Run(). Below is an example.
You have to start with CAppDialog (#include <Controls\Dialog.mqh>) and then create some items (e.g. your combo box). The items must be added to CAppDialog and must be called CAppDialog.Run(). Below is an example.
Hi,
can i ask how to handle CCombobox event ON_CHANGE in your example?
if we have a class it will look something like this:
EVENT_MAP_BEGIN(CForm) ON_EVENT(ON_CHANGE,m_cmbox,OnChange_m_cmbox) EVENT_MAP_END(CAppDialog) void CForm::OnChange_m_cmbox(void) { Print(m_cmbox.Value()); }
but how to handle change in your example?
i'm new to the whole class thing, any help will be appreciated :)
Hi,
can i ask how to handle CCombobox event ON_CHANGE in your example?
if we have a class it will look something like this:
but how to handle change in your example?
i'm new to the whole class thing, any help will be appreciated :)
You should create your custom class (inherited from CAppDialog). Then you have to define a handler for the combo box (OnChangeComboBox) in this class. Don't forget this code is just an example. If you want to create a panel all elements should be members of this panel (class). In this example are they these elements: m_bidcolor, m_bidlabel, m_askcolor, m_asklabel, m_cmbox.
#property strict //+------------------------------------------------------------------+ //| Includes | //+------------------------------------------------------------------+ #include <Controls\Dialog.mqh> #include <Controls\Label.mqh> #include <Controls\Panel.mqh> #include <Controls\ComboBox.mqh> //+------------------------------------------------------------------+ //| Global parameters | //+------------------------------------------------------------------+ int panelXX = 20; int panelYY = 20; int panelWidth = 300; int panelHeight = 300; //+------------------------------------------------------------------+ //| class CAppDialogExample | //+------------------------------------------------------------------+ class CAppDialogExample : public CAppDialog { public: //--- chart event handler virtual bool OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam); private: //--- combo box change event void OnChangeComboBox() {printf("Selected value for ComboBox is %I64d (%s)",m_cmbox.Value(),m_cmbox.Select());} }; EVENT_MAP_BEGIN(CAppDialogExample) ON_EVENT(ON_CHANGE,m_cmbox,OnChangeComboBox) EVENT_MAP_END(CAppDialog) //+------------------------------------------------------------------+ //| Global variabels | //+------------------------------------------------------------------+ //--- Panel itself CAppDialogExample* m_panel; //--- Bid objects CPanel m_bidcolor; CLabel m_bidlabel; //--- Ask objects CPanel m_askcolor; CLabel m_asklabel; //--- ComboBox CComboBox m_cmbox; //+------------------------------------------------------------------+ //| On Init | //+------------------------------------------------------------------+ int OnInit() { m_panel=new CAppDialogExample(); //--- Panel create m_panel.Create(0,"TEST PANEL",0,panelXX,panelYY,panelWidth,panelHeight); //--- Bid label and colors m_bidcolor.Create(0,"Bid Background Color",0,1,1,panelWidth-30,30); m_bidcolor.ColorBackground(clrYellow); m_panel.Add(m_bidcolor); m_bidlabel.Create(0,"Bid Text",0,5,5,0,0); m_bidlabel.Text("Bid "+DoubleToString(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits)); m_bidlabel.Color(clrBlue); m_panel.Add(m_bidlabel); //--- Ask label and colors m_askcolor.Create(0,"Ask Background Color",0,1,101,panelWidth-30,130); m_askcolor.ColorBackground(clrAqua); m_panel.Add(m_askcolor); m_asklabel.Create(0,"Ask Text",0,5,105,0,0); m_asklabel.Text("Ask "+DoubleToString(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits)); m_asklabel.Color(clrRed); m_panel.Add(m_asklabel); //--- ComboBox m_cmbox.Create(0,"ComboBox",0,60,201,panelWidth-90,221); m_cmbox.ItemAdd("Sell"); m_cmbox.ItemAdd("Buy"); m_cmbox.Select(0); // Default value is Sell m_panel.Add(m_cmbox); //--- Run panel m_panel.Run(); return(0); } //+------------------------------------------------------------------+ //| On DeInit | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- Destroy panel m_panel.Destroy(reason); if(CheckPointer(m_panel)==POINTER_DYNAMIC) delete m_panel; //--- Delete all objects ObjectsDeleteAll(0,0); } //+------------------------------------------------------------------+ //| On Calculate | //+------------------------------------------------------------------+ void OnTick() { //--- A very simple bid label m_bidlabel.Text("Bid "+DoubleToString(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits)); //--- A very simple ask label m_asklabel.Text("Ask "+DoubleToString(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits)); } //+------------------------------------------------------------------+ //| On Chart Event | //+------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { //--- Move the panel with the mouse m_panel.ChartEvent(id,lparam,dparam,sparam); } //+------------------------------------------------------------------+
You should create your custom class (inherited from CAppDialog). Then you have to define a handler for the combo box (OnChangeComboBox) in this class. Don't forget this code is just an example. If you want to create a panel all elements should be members of this panel (class). In this example are they these elements: m_bidcolor, m_bidlabel, m_askcolor, m_asklabel, m_cmbox.
thank you Petr for your replay i really appreciate it.
but the problem i'm facing is i'm trying to show/hide a combobox which should be on the same place for CEdit field.
like choosing from typing takeprofit in price, or choosing points from a Combobox, if i press Price button it hides points combobox and show price edit field.
and if i press points button it hides price edit field & show points combobox
** it works fine, except if the panel minimized then maximized again, it show both of Edit field & combobox, while i need the right one depend on which button is activated
both Edit & Combobox should have the same coordinates i only subtract 60 from edit field to show both next to each other
#property strict //+------------------------------------------------------------------+ //| Includes | //+------------------------------------------------------------------+ #include <Controls\Dialog.mqh> #include <Controls\Defines.mqh> #undef CONTROLS_BUTTON_COLOR_BORDER #define CONTROLS_BUTTON_COLOR_BORDER clrNONE #include <Controls\Label.mqh> #include <Controls\Panel.mqh> #include <Controls\ComboBox.mqh> #include <Controls\Button.mqh> //+------------------------------------------------------------------+ //| Global parameters | //+------------------------------------------------------------------+ int panelXX = 20; int panelYY = 20; int panelWidth = 300; int panelHeight = 300; //+------------------------------------------------------------------+ //| class CAppDialogExample | //+------------------------------------------------------------------+ class CAppDialogExample : public CAppDialog { public: //--- chart event handler virtual bool OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam); private: //--- combo box change event void OnChangeComboBox() {printf("Selected value for ComboBox is %I64d (%s)",m_cmbox.Value(),m_cmbox.Select());} void OnClick_m_PriceButton(void); void OnClick_m_PointsButton(void); }; //---On clicking price button change Button's text color to yellow & set it to pressed=true & show Edit field & hide combobox void CAppDialogExample::OnClick_m_PriceButton(void) { Price=true; m_PriceButton.Pressed(true); m_PriceButton.Color(clrYellow); m_PointsButton.Pressed(false); m_PointsButton.Color(clrBlack); m_BuyTPpriceEdit.Show(); m_BuyTPpointsCombobox.Hide(); } //---On clicking Points button change Button's text color to yellow & set it to pressed=true & show combobox & hide Edit field void CAppDialogExample::OnClick_m_PointsButton(void) { Price=false; m_PriceButton.Pressed(false); m_PriceButton.Color(clrBlack); m_PointsButton.Pressed(true); m_PointsButton.Color(clrYellow); m_BuyTPpriceEdit.Hide(); m_BuyTPpointsCombobox.Show(); } EVENT_MAP_BEGIN(CAppDialogExample) ON_EVENT(ON_CHANGE,m_cmbox,OnChangeComboBox) ON_EVENT(ON_CLICK,m_PriceButton,OnClick_m_PriceButton) ON_EVENT(ON_CLICK,m_PointsButton,OnClick_m_PointsButton) EVENT_MAP_END(CAppDialog) //+------------------------------------------------------------------+ //| Global variabels | //+------------------------------------------------------------------+ //--- Panel itself CAppDialogExample* m_panel; //--- Bid objects CPanel m_bidcolor; CLabel m_bidlabel; //--- Ask objects CPanel m_askcolor; CLabel m_asklabel; //--- ComboBox CComboBox m_cmbox; //--- Price / Points buttons to change between 2 options: CButton m_PriceButton; CButton m_PointsButton; //--- Buy TP price edit /points combobox CEdit m_BuyTPpriceEdit; CComboBox m_BuyTPpointsCombobox; bool Price; //+------------------------------------------------------------------+ //| On Init | //+------------------------------------------------------------------+ int OnInit() { m_panel=new CAppDialogExample(); //--- Panel create m_panel.Create(0,"TEST PANEL",0,panelXX,panelYY,panelWidth,panelHeight); //--- Bid label and colors m_bidcolor.Create(0,"Bid Background Color",0,1,1,panelWidth-30,30); m_bidcolor.ColorBackground(clrYellow); m_panel.Add(m_bidcolor); m_bidlabel.Create(0,"Bid Text",0,5,5,0,0); m_bidlabel.Text("Bid "+DoubleToString(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits)); m_bidlabel.Color(clrBlue); m_panel.Add(m_bidlabel); //--- Ask label and colors m_askcolor.Create(0,"Ask Background Color",0,1,101,panelWidth-30,130); m_askcolor.ColorBackground(clrAqua); m_panel.Add(m_askcolor); m_asklabel.Create(0,"Ask Text",0,5,105,0,0); m_asklabel.Text("Ask "+DoubleToString(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits)); m_asklabel.Color(clrRed); m_panel.Add(m_asklabel); //--- ComboBox m_cmbox.Create(0,"ComboBox",0,60,201,panelWidth-90,221); m_cmbox.ItemAdd("Sell"); m_cmbox.ItemAdd("Buy"); m_cmbox.Select(0); // Default value is Sell m_panel.Add(m_cmbox); //------------------------------------------------------------------------------------------------------------------- my changes start here: color m_PriceButtonTxtColor,m_PointsButtonTxtColor; if(Price==true) { m_PriceButtonTxtColor=clrYellow; m_PointsButtonTxtColor=clrBlack; } else { m_PriceButtonTxtColor=clrBlack; m_PointsButtonTxtColor=clrYellow; } //--- Price button int Gap=10, PanelCenterX=(panelWidth-panelXX)/2, ButtonWidth=50, ButtonHeight=20; m_PriceButton.Create(0,"m_PriceButton",0,PanelCenterX-(ButtonWidth+Gap) ,panelHeight-170 , PanelCenterX-Gap , panelHeight-170+ButtonHeight ); m_PriceButton.Text("Price"); m_PriceButton.ColorBackground(clrLightCoral); m_PriceButton.Font("Arial Bold"); m_PriceButton.FontSize(8); m_PriceButton.Color(m_PriceButtonTxtColor);//text color m_PriceButton.Locking(true); m_PriceButton.Pressed(Price); m_panel.Add(m_PriceButton); //--- Points button m_PointsButton.Create(0,"m_PointsButton",0,PanelCenterX+Gap,panelYY+110, PanelCenterX+(ButtonWidth+Gap) , panelYY+110+ButtonHeight ); m_PointsButton.Text("Points"); m_PointsButton.ColorBackground(clrLightCoral); m_PointsButton.Font("Arial Bold"); m_PointsButton.FontSize(8); m_PointsButton.Color(m_PointsButtonTxtColor);//text color m_PointsButton.Locking(true); m_PointsButton.Pressed(!Price); m_panel.Add(m_PointsButton); //--- Edit Field for TP as a price: //should have the same X coords as the combobox but i added -60 to show the problem m_BuyTPpriceEdit.Create(0,"m_BuyTPpriceEdit",0,PanelCenterX-(ButtonWidth/2)-60 ,panelYY+135 , PanelCenterX+(ButtonWidth/2)-60 , panelYY+135+ButtonHeight); m_BuyTPpriceEdit.Text( DoubleToString(0,_Digits) ); m_BuyTPpriceEdit.FontSize(9); m_BuyTPpriceEdit.TextAlign(ALIGN_CENTER); if(Price) m_BuyTPpriceEdit.Show(); else m_BuyTPpriceEdit.Hide(); m_panel.Add(m_BuyTPpriceEdit); //--- Combobox for TP as Points: m_BuyTPpointsCombobox.Create(0,"m_BuyTPpointsCombobox",0,PanelCenterX-(ButtonWidth/2) ,panelYY+135 , PanelCenterX+(ButtonWidth/2) , panelYY+135+ButtonHeight); for(int i=1;i<21;i++) { m_BuyTPpointsCombobox.ItemAdd(IntegerToString(i*10)); } if(Price) m_BuyTPpointsCombobox.Hide(); else m_BuyTPpointsCombobox.Show(); m_panel.Add(m_BuyTPpointsCombobox); //--- Run panel m_panel.Run(); return(0); } //+------------------------------------------------------------------+ //| On DeInit | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- Destroy panel m_panel.Destroy(reason); if(CheckPointer(m_panel)==POINTER_DYNAMIC) delete m_panel; //--- Delete all objects ObjectsDeleteAll(0,0); } //+------------------------------------------------------------------+ //| On Calculate | //+------------------------------------------------------------------+ void OnTick() { //--- A very simple bid label m_bidlabel.Text("Bid "+DoubleToString(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits)); //--- A very simple ask label m_asklabel.Text("Ask "+DoubleToString(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits)); } //+------------------------------------------------------------------+ //| On Chart Event | //+------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { //--- Move the panel with the mouse m_panel.ChartEvent(id,lparam,dparam,sparam); } //+------------------------------------------------------------------+
I strongly recommend the EasyAndFast GUI library to anyone dealing with graphism
There's different versions of the package so beware, once installed you'll be able to deal with controls very easily & fast (hahaha !) - it's a must have for whoever isn't good with graphical stuffs.
You may also have to edit it for some controls to work like you expect it to.
Check it out !
- www.mql5.com
I strongly recommend the EasyAndFast GUI library to anyone dealing with graphism
There's different versions of the package so beware, once installed you'll be able to deal with controls very easily & fast (hahaha !) - it's a must have for whoever isn't good with graphical stuffs.
You may also have to edit it for some controls to work like you expect it to.
Check it out !
thank you, it looks great.
i'm only having a small problem with Show() / Hide()
my EA is almost 8k lines, i can't start from scratch applying new include file
i just need a fix or a workaround :)
thank you Petr for your replay i really appreciate it.
but the problem i'm facing is i'm trying to show/hide a combobox which should be on the same place for CEdit field.
like choosing from
typing takeprofit in price, or choosing points from a Combobox, if i press Price button it hides points combobox and show price edit
field.
and if i press points button it hides price edit field & show points combobox
** it works fine, except if the
panel minimized then maximized again, it show both of Edit field & combobox, while i need the right one depend on which button is
activated
both Edit & Combobox should have the same coordinates i only subtract 60 from edit field to show both next to each other
As I said this is an example. It isn't a good design for a real panel. But if you want a fast workaround you can overwrite the Maximize function.
class CAppDialogExample : public CAppDialog { public: //--- chart event handler virtual bool OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam); virtual void Maximize(void); private: //--- combo box change event void OnChangeComboBox() {printf("Selected value for ComboBox is %I64d (%s)",m_cmbox.Value(),m_cmbox.Select());} void OnClick_m_PriceButton(void); void OnClick_m_PointsButton(void); }; void CAppDialogExample::Maximize(void) { CAppDialog::Maximize(); if(Price) { m_BuyTPpriceEdit.Show(); m_BuyTPpointsCombobox.Hide(); } else { m_BuyTPpriceEdit.Hide(); m_BuyTPpointsCombobox.Show(); } }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I am having hard time creating a panel with the control libraries on mt4, this is the first time i am using them.
I created a rectangle lbl as background and a normal combo box to switch between buy and sell orders, i have tried a lot of ways to pull this off, but seems to have a problem.
The List is filled with the values I wanted, the button reacts when i click, but only the bitmap changes, the list is not opened or closed. I printed out everything i can think of, both in the EA and libraries, but seems to be ok(apparently its not ok).
This is the code i am using to create the box and fill values, in the beginning i have included the files.
I belive there may be more to this except the methods i am using but lets see.
Id be grateful if somebody helps with this !
Thanks in advance