Disable OBJ_BUTTON

metaRaider  

I have created a new button object using...

ObjectCreate(ChartID(), "TestButton", OBJ_BUTTON, 0, 0, 0);

There are certain instances where I would like to disable this button, so is it possible to disable this button object so that it cannot be clicked?

So far I can only see 2 options...

  1. Wait for it to be clicked and then reset the state (OBJPROP_STATE property).
  2. Add a button image on top of the button and then set the OBJPROP_ZORDER property to prevent the button from receiving the input.

Am I overlooking something, or are these my only options?


Carlos Moreno Gonzalez  

You can always "do nothing" in the "OnChartEvent" function when the button is clicked under those conditions, controlling what's happening. All clicks will be ignored. Something like...

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 mouse has been clicked on the graphic object
        if(id == CHARTEVENT_OBJECT_CLICK) {

		// My button
		if(sparam == MY_BUTTON_NAME) {
			if(MyCondition())
                        	//Do something
			else 
                        	//Do something else
		}
   	}
}
metaRaider  
Carlos Moreno Gonzalez #:

You can always "do nothing" in the "OnChartEvent" function when the button is clicked under those conditions, controlling what's happening. All clicks will be ignored. Something like...

Hi, thanks for that.

I should have been more explicit because it is more of a visual thing. By the time you get to perform any processing, the button visual has already changed.

Carlos Moreno Gonzalez  
metaRaider #:

Hi, thanks for that.

I should have been more explicit because it is more of a visual thing. By the time you get to perform any processing, the button visual has already changed.

Not necessarily. Only if you add some background, etc. You control the background color and the font. Or I'm not understanding your issue. Some screenshots, maybe?

metaRaider  
Carlos Moreno Gonzalez #:

Not necessarily. Only if you add some background, etc. You control the background color and the font. Or I'm not understanding your issue. Some screenshots, maybe?

Here is an image where I have clicked the minus (-) button on the image...


The value does not go below 0.25%, so when it hits this value, I want to disable the button. The image you can see was captured by setting a break point in the debugger. Had I not set a break point then the code would have reset the button state, returning the image to this...

So basically, MT5 is processing the button click visuals before allowing any user code to perform any button click processing. What I would like to do is to totally disable the button so that nothing happens when you click on the button.

Hope that helps

Reason: