OnChartEvent - manage button clicks

 

Hi,

I have the following question related to the button click events within the OnChartEvent function.

This is the scenario:

- I have created a panel and a button should show / hide the button.

- The button is an bmpButton, and the image should be different when the panel is shown, and when it is hidden

So this means, each time I click on the button, the other image should be applied to the button.

This is my code:

void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
    


   MyInterface.OnEvent(id,lparam,dparam,sparam);
     
   if(id==CHARTEVENT_OBJECT_CLICK && sparam=="ManagedOrders")
     {
      if(Dialog2.IsVisible()==true){
         Dialog2.Hide();
         ButtonActiveOrders.BmpOnName("\\Image\\NotSelected.bmp");
      }else{
         Dialog2.Show();
         ButtonActiveOrders.BmpOffName("\\Image\\Selected.bmp");
      }
//+------------------------------------------------------------------+
// chart event reset button state
//+------------------------------------------------------------------+
         ObjectSetInteger(0,sparam,OBJPROP_STATE,0);
         Sleep(100);
         ChartRedraw();
//+------------------------------------------------------------------+
     }
  }

This is happening with the code provided above:

It loads the button well, and if I press the button the other image will appear (Selected.bmp). However, it will not change back to NotSelected.bmp if I click on the button again. If I press the mouse button, and hold the mouse button, I see the NotSelected.bmp. However, as soon as I release the mouse button I get the Selected.bmp.

What do I do wrong? How should I manage those mouse events?

Thanks for your support in advance.

Kind regards,

Victor

 

Forum on trading, automated trading systems and testing trading strategies

BmpButton - Image dont appear

Victor Christiaanse, 2022.10.26 10:45

Well, then we both see it different. I see a question about a picture not showing on the chart, or how to handle the click event to change the picture as two different questions. For that reason, I reased a new topic as I wasnt sure if anyone was looking into my question as it was different (and I didnt got any responses yet). It was not done out of a selfish action, just because I found it different questions and I got no responses (which is very uncommon on this forum).


Yes it is. You are not active on the forum helping anyone. Considering you are a market seller, perhaps pay someone instead of begging for help.

 
Victor Christiaanse:

Hi,

I have the following question related to the button click events within the OnChartEvent function.

This is the scenario:

- I have created a panel and a button should show / hide the button.

- The button is an bmpButton, and the image should be different when the panel is shown, and when it is hidden

So this means, each time I click on the button, the other image should be applied to the button.

This is my code:


This is happening with the code provided above:

It loads the button well, and if I press the button the other image will appear (Selected.bmp). However, it will not change back to NotSelected.bmp if I click on the button again. If I press the mouse button, and hold the mouse button, I see the NotSelected.bmp. However, as soon as I release the mouse button I get the Selected.bmp.

What do I do wrong? How should I manage those mouse events?

Thanks for your support in advance.

Kind regards,

Victor

I found the issue. For others that experience the same, hereby the solution:

Put the following into the OnInit() to set the Pressed and the Not Pressed status:

   ButtonActiveOrders.BmpOnName("\\Image\\Selected.bmp");
   ButtonActiveOrders.BmpOffName("\\Image\\NotSelected.bmp");

In the OnChartEvent function, set the status of the BmpButton:

      if(ObjectClick=="ManagedOrders") {
         if(Dialog2.IsVisible()==true){
            Dialog2.Hide();
            ButtonActiveOrders.Pressed(False);
         }else{
            Dialog2.Show();
            ButtonActiveOrders.Pressed(True);
         }
      }

Hope this helps others in future.

 
Enrique Dangeroux #:

Yes it is. You are not active on the forum helping anyone. Considering you are a market seller, perhaps pay someone instead of begging for help.

Just to clarify, not to start a discussion. I got zero responses to my second question, as the title of the other topic was related to my first question. The second question I had was a different one.

I pay for help / support regularly using the freelance service, but the whole point of the forum is to help each other in case you have just a small question. Sometimes you overlook something.