Edit box blinks when Mouse Move

 
Anyone faced such issue? When edit box is selected and being edited, it is blinking as long as mouse moves. Once end edit it stops blinking. 
 

Do not double post!

I have deleted your duplicated topic.

 

So, the problem is ChartRedraw() on ChartEvent Mouse Move. That means when you click edit box and move the mouse, it is redrawing chart on each mouse move. This is why edit box is blinking, i.e. refreshing.

One of the solution is to set a bool EditBoxActive, which will be true when edit object clicked and false on endedit. And in ChartEvent Mouse Move call ChartRedraw() if  EditBoxActive is false. But in this case the rest of events related to Mouse Move are lagging. 

Is there any other idea how it can be solved?

 

Mine blinks without the mouse moving.


I've tracked down every superfluous ChartRedraw() in indicators and ChartRedraw() in the panel and its include files, and also any calls to .Redraw() in the classes.  It also does not seem to be related to incoming ticks.

Currently for debugging, in the indicator (it is a Panel in an indicator), I am print/logging any OnChartEvent()s that I'm not already trapping for, and the selected edit text blinks even without any events printing to the log.

I'm at a loss as to what to look for next.

 
Christian Berrigan #:

Mine blinks without the mouse moving.


I've tracked down every superfluous ChartRedraw() in indicators and ChartRedraw() in the panel and its include files, and also any calls to .Redraw() in the classes.  It also does not seem to be related to incoming ticks.

Currently for debugging, in the indicator (it is a Panel in an indicator), I am print/logging any OnChartEvent()s that I'm not already trapping for, and the selected edit text blinks even without any events printing to the log.

I'm at a loss as to what to look for next.

I'm facng the same problem.

I've tracked it down to CHART_EVENT_MOUSE_MOVE being set to true....

ChartSetInteger(0, CHART_EVENT_MOUSE_MOVE, true);

I'm trying to find a solution.

If anyone has a fix or ideas please chip in.

 
Narek Kamalyan:
Anyone faced such issue? When edit box is selected and being edited, it is blinking as long as mouse moves. Once end edit it stops blinking. 


Solved, well I found a work around at least.


I found that ChartRedraw() isn't the issue, it's CHART_EVENT_MOUSE_MOVE = true.

I was thinking/tinkering. When you click on an Edit Box, the next action must be to click somewhere or press enter. Every other keystroke will input into the Edit Box.

So why not turn off CHART_EVENT_MOUSE_MOVE whilst inside the Edit Box... Then turn it back on in ENDEDIT.


The following code fixes the issue. NOTE:  I only knocked it out quick to demonstrate the fix.

//+------------------------------------------------------------------+
//|                                          Solved Edit Flicker.mq4 |
//|                                  Copyright 2023, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "None"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window

#include <Controls\Edit.mqh>
CEdit   Ed_Box;


input    double      Default_Num_a    = 50.35;      // Default Number(a)
input    double      Min_a            = 15.44;      // Minimum Number(a)


double   Num_a;

// Assuming an output of real mumber:2DP

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

int OnInit()
{
   // Set Number(a) & check its Minimum val
   Num_a = fmax(Default_Num_a, Min_a);
   
   
   // Track Mouse move events
   ChartSetInteger(0, CHART_EVENT_MOUSE_MOVE, true);
   
   
   // Create Edit-Box & add attributes
   Ed_Box.Create(0, "Edit", 0, 500, 100, 0, 0);
   Ed_Box.Text(DoubleToStr(Num_a, 2));
   Ed_Box.Font("Verdana");
   Ed_Box.FontSize(12);
   Ed_Box.TextAlign(ALIGN_CENTER);
   Ed_Box.Color(clrBlack);
   Ed_Box.ColorBackground(C'234,225,215');
   Ed_Box.ColorBorder(clrDarkGoldenrod);
   Ed_Box.Width(100);
   Ed_Box.Height(30);



   
   
   
   return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+

void OnDeinit(const int reason)
{
   Ed_Box.Destroy(reason);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
//---
   
//--- return value of prev_calculated for next call
   return(rates_total);
}

//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+

void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{
   if(id==CHARTEVENT_OBJECT_CLICK)
   { 
      if(sparam == "Edit")
      {
         // Whilst inside of 'Edit' we can turn off 'CHART_EVENT_MOUSE_MOVE' as the next action HAS to be 'EndEdit'
         ChartSetInteger(0, CHART_EVENT_MOUSE_MOVE, false);
      }
   } // OBJECT_CLICK
   
   
   
   if(id == CHARTEVENT_MOUSE_MOVE)
   {
      if(Ed_Box.Contains((int)lparam, (int)dparam))       Ed_Box.ColorBackground(clrLemonChiffon);
      else                                                Ed_Box.ColorBackground(C'234,225,215');
   } // MOUSE_MOVE
   
   
   
   if(id==CHARTEVENT_OBJECT_ENDEDIT)
   {
      // Turn back on 'CHART_EVENT_MOUSE_MOVE'
      ChartSetInteger(0, CHART_EVENT_MOUSE_MOVE, true);
      
      
      if(sparam == "Edit")
      {
         string Txt = Ed_Box.Text();
         
         
         if(Is_Valid_Dbl(Txt))
         {
            Num_a = fmax(Min_a, StrToDouble(Txt));
            Ed_Box.Text(DoubleToStr(Num_a, 2));
         }
         else
         {
            Ed_Box.Text(DoubleToStr(Default_Num_a, 2));
         }
      }
   } // ENDEDIT
   
   
   
}

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

bool Is_Valid_Dbl(string Txt)
{
   int Cnt_DP = 0;   // # of character full stops.. aka 'decimal point'....  0.0.1 =2      0.0 =1
   for(int i= StringLen(Txt)-1; i>=0; i--)
   {
      int Char_i = StringGetChar(Txt, i);
      if(Char_i == 46)  // full stop/period
      {
         Cnt_DP ++;
         if(Cnt_DP >= 2)
            return(false);
      }   
      if((Char_i > 47 && Char_i < 58)  || Char_i == 46)  // 0 to 9  or  period. 
         continue;
      else
         return(false);
   }
   return(true);
   
}

//+------------------------------------------------------------------+
I'm not sure if this is the way to go, but at least it works. I may be missing something.