Hello Members,
I am trying to get onclick event for the panel and dialogue CButton. But is not working. Its working for other control types like Combo box etc. But not working with buttons.
How to solve this issue?
Thank you in advance.
To create a button on each tick can not work, fix your code
To create a button on each tick can not work, fix your code
Hello Amando,
Thank you for your reply.
I have fixed my code, move the button create part to OnInit().
But still clicking on the button not triggering "CHARTEVENT_OBJECT_CLICK" part.
//+------------------------------------------------------------------+ //| ChartEvent function | //+------------------------------------------------------------------+ void OnChartEvent(const int id, // Event identifier const long& lparam, // Event parameter of long type const double& dparam, // Event parameter of double type const string& sparam) // Event parameter of string type { //--- the left mouse button has been pressed on the chart if(id==CHARTEVENT_CLICK) { Print("The coordinates of the mouse click on the chart are: x = ",lparam," y = ",dparam); } //--- the mouse has been clicked on the graphic object if(id==CHARTEVENT_OBJECT_CLICK) { Print("The mouse has been clicked on the object with name '"+sparam+"'"); } //--- the key has been pressed if(id==CHARTEVENT_KEYDOWN) { Print("The key with code ",int(lparam)," has been pressed"); } //--- the object has been deleted if(id==CHARTEVENT_OBJECT_DELETE) { Print("The object with name ",sparam," has been deleted"); } //--- the object has been created if(id==CHARTEVENT_OBJECT_CREATE) { Print("The object with name ",sparam," has been created"); } //--- the object has been moved or its anchor point coordinates has been changed if(id==CHARTEVENT_OBJECT_DRAG) { Print("The anchor point coordinates of the object with name ",sparam," has been changed"); } //--- the text in the Edit of object has been changed if(id==CHARTEVENT_OBJECT_ENDEDIT) { Print("The text in the Edit field of the object with name ",sparam," has been changed"); } } //+------------------------------------------------------------------+
OBJPROP_ZORDER
so that your button will have priority over the other layers.
OBJPROP_ZORDER | Priority of a graphical object for receiving events of clicking on a chart (CHARTEVENT_CLICK). The default zero value is set when creating an object; the priority can be increased if necessary. When objects are placed one atop another, only one of them with the highest priority will receive the CHARTEVENT_CLICK event. | long |
https://www.mql5.com/en/docs/standardlibrary/controls/cwndobj/cwndobjzorder
- www.mql5.com
Thank you for the code.
Here click on the button, showing its clicking on the "Clientback" instead of "btn" (button name), Why?
your button Description is "Settings", read the documentation
tbt.Text("Settings");
There a couple of codes with panels in the codebase, I suggest, download one and study it
Okay please set
so that your button will have priority over the other layers.
OBJPROP_ZORDER | Priority of a graphical object for receiving events of clicking on a chart (CHARTEVENT_CLICK). The default zero value is set when creating an object; the priority can be increased if necessary. When objects are placed one atop another, only one of them with the highest priority will receive the CHARTEVENT_CLICK event. | long |
https://www.mql5.com/en/docs/standardlibrary/controls/cwndobj/cwndobjzorder
Thank you for the idea,
I did that
tbt.ZOrder(100);
Still its clicking on the layer. Strange issue, for other control types, I can easily check click events. But only for the buttons its not working.
int OnInit() { //--- Panel create m_panel.Create(0,"TEST PANEL",0,panelXX,panelYY,panelWidth,panelHeight); //--- Button tbt.Create(0,"btn",0,100,50,15,20); tbt.ColorBackground(clrAliceBlue); tbt.Text("Settings"); tbt.FontSize(10); tbt.ZOrder(100); m_panel.Add(tbt); //--- Run panel m_panel.Run(); //--- succeed return(INIT_SUCCEEDED); }
do you have any idea what this code in your OnInit is doing?
you create an Panel, and then you create a Button, what have absolut no connection to the panel.
even what ist
tbt.Text=
for the description of the Button use Description
then you Add the button to the Panel?? Did you check if this is working?
and then you have in OnChartevent
m_panel.ChartEvent(id,lparam,dparam,sparam);
did you check the Function?
do you have any idea what this code in your OnInit is doing?
you create an Panel, and then you create a Button, what have absolut no connection to the panel.
even what ist
tbt.Text=
for the description of the Button use Description
then you Add the button to the Panel?? Did you check if this is working?
and then you have in OnChartevent
did you check the Function?
Hello Amando,
Thank you for having patience with me.
I am new to Panel.
m_panel.Add(tbt);
I thought above code connects tbt button with the Panel like other controls.
tbt.Text("Settings");
This .Text is used for button text as mentioned in the standard library.
https://www.mql5.com/en/docs/standardlibrary/controls/cwndobj/cwndobjtext
With OnChartevent I did checked the function as mentioned in the previous message.
Only thing is button is visible on the chart panel. But while clicking on it, its showing its clicking on the "Client back". So I am confused here. Other controls are working fine with Onclick event.
- www.mql5.com
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello Members,
I am trying to get onclick event for the panel and dialogue CButton. But is not working. Its working for other control types like Combo box etc. But not working with buttons.
How to solve this issue?
Thank you in advance.