Panel CButton Onclick ChartEvent not working - page 2

 
Somsri Sarkar #:

Debug the add function.

Add(tbt) is working. Showing button is connected with the panel.

I'm facing a similar issue.. Did you ever come up with a solution?

 
Rick Bird #:

I'm facing a similar issue.. Did you ever come up with a solution?

Add this

m_button.Z_Order(100);

into Controls\Button.mqh file


//+------------------------------------------------------------------+
//| Create a control                                                 |
//+------------------------------------------------------------------+
bool CButton::Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2)
  {
//--- call method of the parent class
   if(!CWndObj::Create(chart,name,subwin,x1,y1,x2,y2))
      return(false);
//--- create the chart object
   if(!m_button.Create(chart,name,subwin,x1,y1,Width(),Height()))
      return(false);
    
   m_button.Z_Order(100);   
//--- call the settings handler
   return(OnChange());
  }
 

Hi,


I'm facing a similar issue. I create all of my controls like this:

bool CGraphicalPanel::CreatePanel(void)
{
   this.Create(NULL,"Panel_name", 0, 40, 450, 40 + InpPanelWidth, 450 + InpPanelHeight);

   ...some more controls here...

   ButtonStepLeft.Create(NULL, "ButtonStepLeft", 0, <some_ugly_positioning_code_here>);
   ButtonStepLeft.Id(8);
   ButtonStepLeft.ZOrder(100);
   ButtonStepLeft.Text("<");
   ButtonStepLeft.Color(InpButtonTextColor);
   ButtonStepLeft.ColorBackground(InpButtonBgColor);
   ButtonStepLeft.FontSize(15);
   ButtonStepLeft.ColorBorder(InpGUIBackgroundColor);
   this.Add(ButtonStepLeft);

   ...and here...

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

So as you can see, each and every of these buttons have the ZOrder property of 100, but the unique properties differ (name, id, etc). I have 15 buttons on my graphical panel, 8 of them does not behave as expected (yap, that's a 50%+ ratio, with the very same properties!).

If I click a button with no object behind it, this happens:

A properly working button looks like this:

A malfunctioning button creates these events:


But if there is an other object behind it the following happens:

Proper button:


malfunctioning button:

 

The object in the background is a VLINE.

In both background object cases, the event handler received information that I was clicked an object (the VLINE), and the button sparam went to the CHARTEVENT_CUSTOM (there is no EventChartCustom() used in the code), which shows the object text in case of a properly working button, and ClientBack in case of a malfunctioning button.

When I hover the mouse over a properly working button, I can see its Object Name as sparam:


But when I do the same for any of the malfunctioning buttons, I do not see anything! The event handler does not notice if anything have happened, so I think something goes wrong during the object creation, the object does not get the sparam properly. This error persists through restarts, recompiles, etc.

Think this might be the case of the original error in the topic, because if you see @Somsri Sarkar showed pics of some ClientBack sparams.

What's going wrong with these controls?

 

Hello,


Sorry, seems the thread does not come up on the feed, so sorry for pinging you guys directly, @amando, @Marco vd Heijden and @Denny Muhammad Zein.

With the more detailed problem explanation, could you please look into it, where could our code go wrong? We'd really appreciate your help.


Properly working button event handler call:

if(id == CHARTEVENT_OBJECT_CLICK && sparam == "ButtonDeleteLast")
{
   ... code to execute ...   
}

Malfunctioning button eventhandler call:

if(id == CHARTEVENT_OBJECT_CLICK && sparam == "ButtonStepLeft")
{
   ... code to execute ...
}

So as you can see nothing unusual here, even the eventhandler call is the same.


Thank you in advance,

J.

 
I'm trying to find where and how the object name is passed as sparam in the parent classes, like WndContainer and WndClient. Not much luck so far, not even sure if it is handled in any of these classes.
 

One more interesting detail:

If I check the Object properties on the chart, I see nothing unusual on the properly created button:


BUT for the button that is not properly visible to the event handler:

What is that? Where does it get that value from? It is identical for all the malfunctioning buttons.

I tried to set the x1,y1,x2,y2 coords explicitly without any calculations, thought that might cause the issue, but it didn't work.

 

Finally I got it. This last bit of info helped. The sparam is passed improperly because of the confusion around the height parameter. I checked how I pass values to the Create function, and if I used

ButtonStepLeft.Create(NULL, "ButtonStepLeft", 0, 10, 245, 35, 55);

so when y1 > y2 (therefore height is calculated in a reverse manner) the height calculation gets messed up, a nonsense value will be generated as height, and sparam will be set as ClientBack.

But as soon as I changed it back to a x1 < x2; y1 < y2 format like this:

ButtonStepLeft.Create(NULL, "ButtonStepLeft", 0, 10, 55, 35, 245);

all of the sudden it got cured.


@Somsri Sarkar check your button.Create statement if it is the case for you.

Reason: