How to change CAppDialog background color? - page 2

 

As a developer I was very frustrated too for not having control over such a useful property, which is backcolor.

Searched the possibilities, and, even not being an OOP expert, decided take the chances and change the TextBox control, including this public method:

   void   SetBackColor(const color clr)  { m_back_color=clr; }

Now it is very easy setting the TextBox background color:

CTextEdit  m_txt;

m_txt.GetTextBoxPointer().SetBackColor(clrYellow);

Now I need to be careful when updating the EasyAndFastGUI package, but I think it is worth
Documentation on MQL5: Language Basics / Preprocessor / Program Properties (#property)
Documentation on MQL5: Language Basics / Preprocessor / Program Properties (#property)
  • www.mql5.com
Program Properties (#property) - Preprocessor - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

You can try this method to add to your derived CAppDialog class:

//+--------------------------------------------------------------------------------------------------------------------------------------------------
//+ Sets AppDialog background color
//+--------------------------------------------------------------------------------------------------------------------------------------------------
void MyAppDialog::ColorBackground(const color clr)
{
    string prefix=Name();
    int total=ControlsTotal();
    for(int i=0;i<total;i++)
    {
        CWnd*obj=Control(i);
        string name=obj.Name();
        if(name==prefix+"Client")
        {
            CWndClient *wndclient=(CWndClient*) obj;
            wndclient.ColorBackground(clr);
            ChartRedraw();
            return;
        }
    }
}


then use it in EA after the creation of AppDialog:

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
    App=new CMyAppDialog();
    App.Create(0,0, //...your params);
    App.ColorBackground(clrYellow);  // new method to change the background color
    App.Run();
    .
    .
    .
}
 

If use Objects Total with ObjecSetInteger I can use OBJPROR_COLOR and OBJPROP_BGCOLOR. This is an example that use in my indicators and EA´s: 


#include <Controls\Dialog.mqh>

#include <Controls\Button.mqh>

#include <Controls\Edit.mqh>

#include <Controls\Label.mqh>



#property indicator_chart_window

#property indicator_plots   0

#property indicator_buffers 1



CAppDialog Panel;





//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit()

  {

//--- indicator buffers mapping





   Panel.Destroy(0);





   if(!Panel.Create(0,"Harmonic Manager",0,5,10,205,310))

     {

      Alert("Error al crear el Panel");

      return (INIT_FAILED);

     }

   else

     {

      int total = ObjectsTotal(0,-1,-1);

      for(int i=0;i<total;i++)

        {

         string Name = ObjectName(0,i,-1,-1);



         if(Extract_rectangle(Name, "ClientBack"))

           {

            ObjectSetInteger(0,Name,OBJPROP_COLOR,clrBlack);

            ObjectSetInteger(0,Name,OBJPROP_WIDTH,3);

            ObjectSetInteger(0,Name,OBJPROP_BGCOLOR,clrWhite);

           }

         if(Extract_rectangle(Name, "Border"))

           {

            ObjectSetInteger(0,Name,OBJPROP_COLOR,clrWhite);

            ObjectSetInteger(0,Name,OBJPROP_BGCOLOR,clrWhite);

           }

         if(Extract_rectangle(Name, "Back") && !Extract_rectangle(Name, "ClientBack"))

           {

            ObjectSetInteger(0,Name,OBJPROP_COLOR,clrMediumTurquoise);

            ObjectSetInteger(0,Name,OBJPROP_BGCOLOR,clrMediumTurquoise);

           }

         if(Extract_rectangle(Name, "Caption"))

           {

            ObjectSetInteger(0,Name,OBJPROP_COLOR,clrBlack);

            ObjectSetString(0,Name,OBJPROP_FONT,"Arial");

            ObjectSetInteger(0,Name,OBJPROP_FONTSIZE, 12);

            

            ObjectSetInteger(0,Name,OBJPROP_BGCOLOR,clrMediumTurquoise);

            ObjectSetInteger(0,Name,OBJPROP_BORDER_COLOR,clrMediumTurquoise);

           }

        }

      Panel.Run();

     }

   return(INIT_SUCCEEDED);

  }



bool Extract_rectangle(string name, string tag)

  {

   if(StringFind(name, tag) == -1)

      return false;

   return true;

  }