Hi, if I create an object text label, how can I get the size (length) of that text in pixels. It similars like TextGetSize function. I have try with OBJPROP_XDISTANCE but it didn't work. Appreciate if you can explain clearly.
Thanks.
I have try it, but the result is 0.
I have try it, but the result is 0.
Yes, I've got same problem when I'm trying to get this value right after creation. But when the chart is rendered and show object, this value become to be right.
objectCreate(oID+"SZ", 0, 0, "XXX", FontSize, FontName, clrBlack); // object creation function dy = (int)ObjectGetInteger(0,oID+"SZ",OBJPROP_YSIZE,0)*2; dx = (int)ObjectGetInteger(0,oID+"SZ",OBJPROP_XSIZE,0);
On first time running (OnInit) this code the dx & dy equal to 0.
But on next tick they have right values. Even WindowRedraw() cannot help.
So, my guess is chart should be rendered by an internal MT4 routine and then we can get such values.
Yes, I've got same problem when I'm trying to get this value right after creation. But when the chart is rendered and show object, this value become to be right.
On first time running (OnInit) this code the dx & dy equal to 0.
But on next tick they have right values. Even WindowRedraw() cannot help.
So, my guess is chart should be rendered by an internal MT4 routine and then we can get such values.
What are you trying to achieve exactly ?
After I created text object label (Label1), I want to put another object label (Label2) after the first label based on first text size (in pixels).
After I created text object label (Label1), I want to put another object label (Label2) after the first label based on first text size (in pixels).
Try this :
//--- input parameters input string font="Arial"; input int fontsize=28; //+------------------------------------------------------------------+ //| Indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- uint w,h; ChartSetInteger(0,CHART_EVENT_OBJECT_CREATE,true); TextSetFont(font,-fontsize*10); string label1_text="First label."; string label2_text="Second label."; //--- CreateLabel("test1",label1_text,100,100); TextGetSize(label1_text,w,h); printf("Label %s width=%u","test1",w); //--- CreateLabel("test2",label2_text,100+w,100); TextGetSize(label2_text,w,h); printf("Label %s width=%u","test2",w); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Create a label | //+------------------------------------------------------------------+ bool CreateLabel(string name,string text,int x,int y) { if(ObjectCreate(0,name,OBJ_LABEL,0,0,0)) { //ObjectSetString(0,name,OBJPROP_NAME ObjectSetString(0,name,OBJPROP_FONT,font); ObjectSetInteger(0,name,OBJPROP_FONTSIZE,fontsize); ObjectSetString(0,name,OBJPROP_TEXT,text); ObjectSetInteger(0,name,OBJPROP_XDISTANCE,x); ObjectSetInteger(0,name,OBJPROP_YDISTANCE,y); } return(true); } //+------------------------------------------------------------------+ //| ChartEvent function | //+------------------------------------------------------------------+ void OnChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam) { if(id==CHARTEVENT_OBJECT_CREATE) { printf("Object create : name %s size=%i",sparam,ObjectGetInteger(0,sparam,OBJPROP_XSIZE)); } } //+------------------------------------------------------------------+ //| Indicator deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { ObjectsDeleteAll(0,-1,OBJ_LABEL); } //+------------------------------------------------------------------+
Try this :
Regards.
Try this :
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi, if I create an object text label, how can I get the size (length) of that text in pixels. It similars like TextGetSize function. I have try with OBJPROP_XDISTANCE but it didn't work. Appreciate if you can explain clearly.
Thanks.