Creating a panel with many single labels and equal distributions on normal and4k display

 

Hi, 

how can I create a panel with many single labels and always the same distance between.

This should work without any changes on a normal pc-display or also on a 4k display. My problem is that I don't know how wide the single labels are.

I can't say that a letter has a definite wide, so there is a big difference between the following 3 letters:

 "iii" and "www" 

 So how can I do such a panel?

 

you could use a font such as courier

Google monospaced fonts for more

 

Latest version 970 has new terminal property TERMINAL_SCREEN_DPI

Check examples.

 

I would use constant size background rectangle label and inside put a normal label.

Here is a script to show you how it could work:

(If you want to make all of this moveable - search recent threads - i asked about it and got right responses.)

//+------------------------------------------------------------------+
//|                                                   Rectlabels.mq4 |
//|                        Copyright 2016, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
int chart_ID;

void OnStart()
{
   chart_ID=0;
   
   int x=50, y=50;
   RectLabelCreate("rect1",x,y,clrBlack,200,40,false);
   RectLabelCreate("rect2",x,y+50,clrBlack,200,40,false);
   RectLabelCreate("rect3",x,y+100,clrBlack,200,40,false);
   
   LabelCreate("label1",x+40,y+10,"Information 1", clrBlack,12);
   LabelCreate("label2",x+40,y+60,"Information 2", clrBlack,12);
   LabelCreate("label3",x+40,y+110,"Information 3", clrBlack,12);
      
   Sleep(1000*10);
   ObjectDelete(chart_ID,"rect1");
   ObjectDelete(chart_ID,"rect2");
   ObjectDelete(chart_ID,"rect3");
   ObjectDelete(chart_ID,"label1");
   ObjectDelete(chart_ID,"label2");
   ObjectDelete(chart_ID,"label3");
}
 
void LabelCreate(string name, int x, int y, string text, color clr, int font_size){
 
 int sub_window=0;
 int height=50;
 int width=100;
 int corner=CORNER_LEFT_UPPER;
 string font="Arial";
 color back_clr=clrBeige;
 color border_clr=clrBlack;
 bool back=false;
 bool state=true;
 bool selection=false;
 bool hidden=true;
 int z_order=0;
 double angle=0.0;
 ENUM_ANCHOR_POINT anchor=ANCHOR_LEFT_UPPER;
//--- reset the error value 
   ResetLastError(); 
//--- create a text label 
 if(!ObjectCreate(chart_ID,name,OBJ_LABEL,sub_window,0,0)) 
 { 
  Print(__FUNCTION__, ": failed to create spread label! Error code = ",GetLastError()); 
  return; 
 } 
//--- set label coordinates 
   ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x); 
   ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y); 
//--- set the chart's corner, relative to which point coordinates are defined 
   ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner); 
//--- set the text 
   ObjectSetString(chart_ID,name,OBJPROP_TEXT,text); 
//--- set text font 
   ObjectSetString(chart_ID,name,OBJPROP_FONT,font); 
//--- set font size 
   ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size); 
//--- set the slope angle of the text 
   ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle); 
//--- set anchor type 
   ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor); 
//--- set color 
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); 
//--- display in the foreground (false) or background (true) 
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); 
//--- enable (true) or disable (false) the mode of moving the label by mouse 
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); 
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); 
//--- hide (true) or display (false) graphical object name in the object list 
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); 
//--- set the priority for receiving the event of a mouse click in the chart 
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); 
//--- successful execution 
} 

void RectLabelCreate(string name, int x, int y, color clr, int width, int height, bool selection){ 
 int sub_window=0;
 int corner=CORNER_LEFT_UPPER;
 string font="Arial";
 color back_clr=clrWhite;
 color border_clr=clrBlack;
 bool back=false;
 bool state=true;
 bool hidden=true;
 int z_order=0;
 ENUM_BORDER_TYPE border=BORDER_FLAT;  
 ENUM_LINE_STYLE style=STYLE_SOLID; 
 int line_width=4; 
//--- reset the error value 
   ResetLastError(); 
//--- create a rectangle label 
   if(!ObjectCreate(chart_ID,name,OBJ_RECTANGLE_LABEL,sub_window,0,0)){ 
      Print(__FUNCTION__, ": failed to create a rectangle label! Error code = ",GetLastError()); 
      return; 
   } 
//--- set label coordinates 
   ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x); 
   ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y); 
//--- set label size 
   ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width); 
   ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height); 
//--- set background color 
   ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,back_clr); 
//--- set border type 
   ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_TYPE,border); 
//--- set the chart's corner, relative to which point coordinates are defined 
   ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner); 
//--- set flat border color (in Flat mode) 
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); 
//--- set flat border line style 
   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style); 
//--- set flat border width 
   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,line_width); 
//--- display in the foreground (false) or background (true) 
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); 
//--- enable (true) or disable (false) the mode of moving the label by mouse 
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); 
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); 
//--- hide (true) or display (false) graphical object name in the object list 
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); 
//--- set the priority for receiving the event of a mouse click in the chart 
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); 
//--- successful execution 
} 
//+------------------------------------------------------------------+
Reason: